:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1d222c;
  --text: #e8ecf1;
  --muted: #8892a6;
  --line: #262c38;
  --accent: #6aaa64;
  --warn: #c9b458;
  --bad: #787c7e;
  --danger: #c0392b;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --r: 14px;
  --tile: clamp(44px, 11vw, 62px);
  --gap: 6px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2030 0%, var(--bg) 60%) fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 32px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.brand-left { display:flex; align-items:center; gap:10px; }
.logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #6aaa64, #4f8a4a);
  display: grid; place-items: center; color: white; font-weight: 900;
  box-shadow: var(--shadow);
}
.sub { color: var(--muted); font-size: 13px; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); border-radius: 10px; padding: 8px 10px; cursor: pointer;
  font-size: 13px;
}
.icon-btn:hover { background: var(--panel-2); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 6px; letter-spacing: .04em; text-transform: uppercase; }
input[type="text"], select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="text"]:focus, select:focus {
  border-color: #3a82f7;
  box-shadow: 0 0 0 3px rgba(58,130,247,.15);
}

button {
  appearance: none;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 700;
  padding: 13px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 15px;
  letter-spacing: .01em;
  transition: transform .05s ease, filter .15s ease, background .15s ease;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(1px); }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.danger { background: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.mode {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, transform .15s, background .15s;
}
@media (hover: hover) {
  .mode:hover { border-color: #3a82f7; }
}

/* Per-mode accent colors — keep visually distinct even when selected. */
.mode[data-mode="turn"]    { --mode-color: #6aaa64; }  /* green */
.mode[data-mode="sudden"]  { --mode-color: #e07a4a; }  /* warm orange */
.mode[data-mode="classic"] { --mode-color: #7a8df7; }  /* indigo */

.mode .mode-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: inline-grid; place-items: center;
  background: color-mix(in srgb, var(--mode-color) 18%, transparent);
  color: var(--mode-color);
  margin-bottom: 8px;
}
.mode h3 { color: var(--mode-color); }

.mode.selected {
  border-color: var(--mode-color);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--mode-color) 18%, transparent),
    transparent);
  box-shadow: 0 0 0 1px var(--mode-color) inset;
}
.mode.selected h3::before {
  content: "✓ ";
  color: var(--mode-color);
}
.mode h3 { margin: 0 0 6px; font-size: 15px; }
.mode p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }

.menu-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px;
}
@media (max-width: 520px) { .menu-grid { grid-template-columns: 1fr; } }

.code-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 20px;
  letter-spacing: .35em;
  background: var(--panel-2);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  text-align: center;
  text-transform: uppercase;
}

.players { display: grid; gap: 8px; }
.player {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--accent); box-shadow: 0 0 0 4px rgba(106,170,100,.18); }
.tag { font-size: 11px; color: var(--muted); padding: 2px 6px; border: 1px solid var(--line); border-radius: 999px; }

.myWrap {
  display: flex;
  justify-content: center;
  margin-top: 4px;
}

.oppBar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(120px, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding: 8px 2px;
  margin-bottom: 6px;
  scrollbar-width: thin;
}
.opp {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.opp.turn { box-shadow: 0 0 0 2px var(--warn) inset; }
.oppHead {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
}
.oppName {
  flex: 1; min-width: 0;
  font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.oppStatus { color: var(--muted); font-size: 11px; }
.oppRows {
  display: flex; flex-direction: column; gap: 3px;
}
.oppRow { display: flex; gap: 3px; }
.oppTile {
  flex: 1;
  height: 8px;
  border-radius: 2px;
  background: transparent;
  border: 1px solid var(--line);
}
.oppTile.correct { background: var(--accent); border-color: var(--accent); }
.oppTile.present { background: var(--warn); border-color: var(--warn); }
.oppTile.absent { background: var(--bad); border-color: var(--bad); }

.game {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.boardCard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  position: relative;
}
.boardCard.me { border-color: rgba(106,170,100,.5); }
.boardCard.turn { box-shadow: 0 0 0 2px var(--warn) inset; }
.boardName { font-weight: 700; }
.board {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: var(--gap);
}
.tile {
  width: var(--tile); height: var(--tile);
  border: 2px solid var(--line);
  border-radius: 8px;
  display: grid; place-items: center;
  text-transform: uppercase;
  font-size: calc(var(--tile) * 0.42);
  font-weight: 800;
  background: transparent;
  color: var(--text);
  transition: transform .15s ease;
}
.tile.filled { border-color: #3a4252; }
.tile.correct { background: var(--accent); border-color: var(--accent); color: white; }
.tile.present { background: var(--warn); border-color: var(--warn); color: white; }
.tile.absent { background: var(--bad); border-color: var(--bad); color: white; }
.row-extend .tile { animation: drop .35s ease both; }
@keyframes drop {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.tile.flip { animation: flip .55s ease both; }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
.tile.shake { animation: shake .35s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.tile.pop { animation: pop .15s ease; }
@keyframes pop {
  from { transform: scale(.85); }
  to { transform: scale(1); }
}

.gameHeader {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 10px;
}
.gameMeta { display: flex; gap: 8px; align-items: center; }
.badge {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
}
.badge.live { color: var(--accent); border-color: rgba(106,170,100,.4); }

.keyboard {
  margin-top: 16px;
  display: flex; flex-direction: column; gap: 6px;
  align-items: center; user-select: none;
  position: sticky; bottom: 0;
  padding-top: 8px; padding-bottom: max(4px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
}
.kbRow { display: flex; gap: 6px; }
.key {
  min-width: 32px; height: 52px; padding: 0 10px;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font-weight: 700; font-size: 14px;
  display: grid; place-items: center; cursor: pointer;
  text-transform: uppercase;
  transition: background .15s, color .15s, border-color .15s;
}
.key.wide { padding: 0 12px; font-size: 12px; }
.key.correct { background: var(--accent); border-color: var(--accent); color: white; }
.key.present { background: var(--warn); border-color: var(--warn); color: white; }
.key.absent { background: var(--bad); border-color: var(--bad); color: white; }
.key:active { transform: translateY(1px); }

.keyboard.locked .key {
  opacity: .45;
  pointer-events: none;
  filter: grayscale(.4);
}

.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel); color: var(--text);
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  font-size: 14px; z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px; margin-bottom: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.banner strong { color: var(--accent); }

.endOverlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 9;
  padding: 16px;
  animation: fade .25s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.endCard {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 22px;
  max-width: 380px; width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.endCard h2 { margin: 0 0 4px; }
.endCard .target {
  display: inline-block; font-family: ui-monospace, Menlo, monospace;
  letter-spacing: .3em; text-transform: uppercase;
  background: var(--panel-2); padding: 6px 10px; border-radius: 8px;
  margin: 8px 0 14px;
}
.endCard .btnRow { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.winList {
  list-style: none;
  margin: 6px 0 14px;
  padding: 0;
  text-align: left;
  display: flex; flex-direction: column; gap: 6px;
}
.winList li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.winList li.self { border-color: rgba(106,170,100,.5); }
.winList .rank { font-weight: 800; color: var(--muted); text-align: center; }
.winList li.top .rank { color: var(--accent); }
.winList li.top { border-color: rgba(106,170,100,.4); }
.winList .who { font-weight: 600; }
.winList .meta { color: var(--muted); font-size: 13px; }

.modalOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: grid; place-items: center;
  padding: 16px;
  z-index: 20;
  animation: fade .18s ease both;
}
.modalOverlay.closing { animation: fadeOut .12s ease both; }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
.modalCard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  max-width: 380px; width: 100%;
  box-shadow: var(--shadow);
  animation: modalIn .18s ease both;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.modalCard h2 { margin: 0 0 6px; font-size: 18px; }
.modalCard .modalBody { margin: 0 0 14px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.modalBtns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modalBtns button { padding: 10px 14px; font-size: 14px; }

.statGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .v { font-size: 22px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

.linkRow { display: flex; gap: 8px; align-items: stretch; }
.linkRow input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

.icon-action {
  appearance: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  transition: background .15s, border-color .15s, transform .05s;
}
.icon-action:hover { background: var(--panel); border-color: #3a4252; }
.icon-action:active { transform: translateY(1px); }
.icon-action svg { display: block; }

.share {
  display: grid; gap: 10px;
}

.center { text-align: center; }
.muted { color: var(--muted); font-size: 13px; }

hr.sep { border: none; border-top: 1px solid var(--line); margin: 6px 0; }

@media (max-width: 720px) {
  .game { grid-template-columns: 1fr; }
  .h1 { font-size: 22px; }
}
