:root {
  --bg: #17142b;
  --panel: #241f40;
  --panel-2: #2f2952;
  --text: #f1eefb;
  --muted: #a8a1c9;
  --accent: #f2c14e;
  --card: #fdfdfb;
  --island: #2f6fd1;
  --forest: #2e8b47;
  --mountain: #c8442f;
  --plains: #e6d48e;
  --swamp: #5a4470;
  --event: #6d6880;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
}

main { max-width: 960px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }
.screen { display: flex; flex-direction: column; gap: 12px; }
#home, #lobby { max-width: 320px; margin: 10vh auto 0; text-align: center; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 0.2em; }

h1 { margin: 0 0 12px; color: var(--accent); }
.label, .hint { margin: 0; color: var(--muted); font-size: 14px; }
.code { font-size: 48px; font-weight: 700; letter-spacing: 0.25em; color: var(--accent); }
.toggle { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--muted); }

input, button {
  font: inherit;
  padding: 12px 14px;
  border-radius: 8px;
  border: none;
}
input { background: var(--card); color: #111; }
button { background: var(--accent); color: #222; font-weight: 600; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
button.secondary { background: transparent; color: var(--muted); border: 1px solid var(--muted); }
button.small { padding: 8px 12px; font-size: 14px; }
button.ability { background: #8fd3a8; }
button.end { background: var(--text); margin-left: auto; }
button.link { background: none; color: var(--accent); padding: 0 0 0 10px; text-decoration: underline; }

ul { list-style: none; margin: 0; padding: 0; }
#playerList li { background: var(--panel); padding: 10px; border-radius: 8px; margin-bottom: 6px; }

/* ---------- table ---------- */

#opponents {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}
.panel, #mine {
  background: var(--panel);
  border-radius: 10px;
  padding: 8px;
  border: 2px solid transparent;
}
.panel.active { border-color: var(--accent); }
.panel.offline { opacity: 0.55; }
.panel.targeted { border-color: #ff7a7a; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 14px;
}
.panel-head span { color: var(--muted); white-space: nowrap; }

.area { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.tower { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tower-head {
  font-size: 11px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot {
  height: 22px;
  border-radius: 4px;
  border: 1px dashed #4a4470;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b6590;
  cursor: pointer;
}
.slot.filled { border-style: solid; color: #fff; font-weight: 700; }
.t-island .slot.part { background: var(--island); }
.t-forest .slot.part { background: var(--forest); }
.t-mountain .slot.part { background: var(--mountain); }
.t-plains .slot.part { background: var(--plains); color: #333; }
.t-swamp .slot.part { background: var(--swamp); }
.slot.ct { background: repeating-linear-gradient(45deg, #777, #777 4px, #999 4px, #999 8px); }
.targeted { outline: 2px solid #ff7a7a; outline-offset: 1px; }

#board {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 16px;
  padding: 8px 0;
}
#tableau { display: flex; gap: 6px; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }

#status { text-align: center; font-weight: 600; color: var(--muted); }
#status.mine { color: var(--accent); }

#mine .area { max-width: 420px; }
#mine .slot { height: 28px; }

/* ---------- cards ---------- */

.card {
  position: relative;
  width: 64px;
  height: 90px;
  background: var(--card);
  color: #111;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  text-align: center;
  padding: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
  user-select: none;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.1s;
}
.card b { font-size: 12px; line-height: 1.1; }
.card.part { color: #fff; }
.card.part.t-island { background: var(--island); }
.card.part.t-forest { background: var(--forest); }
.card.part.t-mountain { background: var(--mountain); }
.card.part.t-plains { background: var(--plains); color: #333; }
.card.part.t-swamp { background: var(--swamp); }
.card.event { background: var(--event); color: #fff; }
.card.event b { font-size: 11px; }
.card.back {
  background: repeating-linear-gradient(135deg, #3a3170, #3a3170 6px, #2c2558 6px, #2c2558 12px);
  color: var(--accent);
  font-weight: 700;
  cursor: default;
}
.card.event-back { background: repeating-linear-gradient(135deg, #5a5570, #5a5570 6px, #47435a 6px, #47435a 12px); color: #fff; }
.card.empty { background: transparent; border: 2px dashed #4a4470; box-shadow: none; cursor: default; }
.card.clickable { cursor: pointer; box-shadow: 0 0 0 2px var(--accent); }
.card.clickable:hover { transform: translateY(-4px); }
.card.selected { border-color: var(--accent); transform: translateY(-8px); }
.card .order {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--accent);
  color: #222;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-style: normal;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

#hand { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding-top: 10px; }
#selInfo { text-align: center; font-size: 14px; min-height: 20px; }
#actions { display: flex; flex-wrap: wrap; gap: 6px; }

#logBox { background: var(--panel); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
#logBox summary { cursor: pointer; color: var(--muted); }
#log { max-height: 160px; overflow-y: auto; margin-top: 6px; }
#log li { padding: 2px 0; color: var(--muted); }
#log li:first-child { color: var(--text); }

/* ---------- modal & toast ---------- */

#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.modal-box {
  background: var(--panel-2);
  border-radius: 12px;
  padding: 16px;
  max-width: 520px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
}
#modalPrompt { margin: 0; }
#modalOptions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding-top: 8px; }

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 20;
  max-width: calc(100% - 32px);
}

@media (max-width: 520px) {
  .card { width: 56px; height: 80px; }
  #opponents { grid-template-columns: 1fr; }
}
