:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f2430;
  --ink: #f4f7fb;
  --muted: #9aa4b2;
  --line: #2c3340;
  --accent: #2dd4bf;
  --accent-dark: #14b8a6;
  --blue: #60a5fa;
  --red: #fb7185;
  --gold: #fbbf24;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background:
    radial-gradient(circle at 18% 0%, rgba(45, 212, 191, .18), transparent 28rem),
    radial-gradient(circle at 88% 8%, rgba(96, 165, 250, .14), transparent 24rem),
    var(--bg);
  color: var(--ink);
}

button, input, select { font: inherit; }

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 15px;
  background: var(--accent);
  color: #07110f;
  font-weight: 900;
  cursor: pointer;
}

button:hover { background: var(--accent-dark); }
button.selected { background: var(--blue); color: #07111f; }
button:disabled { cursor: not-allowed; opacity: .48; }

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #10131a;
  color: var(--ink);
  outline: none;
}

input::placeholder { color: #6f7a89; }

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, .16);
}

.shell {
  width: min(1240px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0;
}

.hero {
  min-height: 132px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(110deg, rgba(23, 26, 33, .88), rgba(23, 26, 33, .62)),
    url("https://images.unsplash.com/photo-1516321318423-f06f85e504b3?auto=format&fit=crop&w=1400&q=80");
  background-size: cover;
  background-position: center;
}

.brand span,
.label,
.stats span,
.panel-head span,
.subhead,
.inventory span {
  display: block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--muted);
}

.brand span { color: var(--accent); }

.brand p {
  margin-top: 8px;
  color: #c8d1dc;
  font-weight: 700;
}

h1, h2, p { margin: 0; }

h1 {
  margin-top: 4px;
  font-size: clamp(34px, 6vw, 66px);
  line-height: 1;
  letter-spacing: 0;
}

h2 { font-size: 17px; }

.session-card {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px;
  background: rgba(15, 17, 21, .78);
  backdrop-filter: blur(10px);
}

.session-card strong { font-size: 22px; }

.auth-card {
  width: min(420px, 100%);
}

.auth-form {
  display: grid;
  gap: 8px;
}

.auth-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.auth-actions button {
  padding: 0 10px;
}

#registerButton,
#logoutButton {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

#registerButton:hover,
#logoutButton:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.compact-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.room-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 310px;
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.panel,
.game-board {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 26, 33, .94);
  box-shadow: 0 18px 50px rgba(0,0,0,.25);
}

.panel { padding: 16px; }

.game-board {
  min-height: 650px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-head,
.game-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.panel-head {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.subhead {
  margin: 16px 0 8px;
  color: var(--accent);
}

.person-list,
.shop-list,
ol {
  display: grid;
  gap: 8px;
}

.person,
li,
.stats div,
.match-strip div,
.inventory div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.person {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  min-height: 54px;
}

.person > div {
  min-width: 0;
}

.person strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person span,
li small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.empty-person {
  grid-template-columns: minmax(0, 1fr);
}

.busy-person {
  opacity: .62;
}

.person button {
  min-height: 34px;
  padding: 0 10px;
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.person button:hover { border-color: var(--accent); color: var(--accent); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 82px);
  gap: 8px;
}

.stats div { padding: 9px 10px; }

.stats strong {
  display: block;
  margin-top: 2px;
  font-size: 24px;
  line-height: 1;
}

.match-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.match-strip div { padding: 12px; }

.match-strip strong {
  display: block;
  margin-top: 5px;
  color: var(--red);
  font-size: 22px;
  letter-spacing: 0;
}

#timeLeft {
  color: var(--gold);
}

.stake-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px 110px;
  gap: 8px;
  align-items: center;
}

.toggle {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10131a;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.letter-stage {
  flex: 1;
  min-height: 330px;
  display: grid;
  grid-template-columns: minmax(190px, .72fr) minmax(260px, 1fr);
  gap: 22px;
  align-items: center;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(45, 212, 191, .12), rgba(96, 165, 250, .08)),
    #11151d;
}

.letter-card {
  display: grid;
  place-items: center;
  width: min(100%, 230px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 1px solid rgba(45, 212, 191, .35);
  border-radius: 8px;
  background: #07110f;
  color: var(--accent);
  font-size: clamp(84px, 14vw, 142px);
  font-weight: 950;
  box-shadow: inset 0 0 40px rgba(45, 212, 191, .08), 0 20px 44px rgba(0,0,0,.3);
}

.instruction {
  display: grid;
  gap: 12px;
}

#turnLabel {
  width: fit-content;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(45, 212, 191, .14);
  color: var(--accent);
  border: 1px solid rgba(45, 212, 191, .28);
  font-size: 13px;
  font-weight: 900;
}

#promptText {
  font-size: clamp(24px, 4vw, 40px);
  line-height: 1.16;
  letter-spacing: 0;
}

#message {
  min-height: 52px;
  color: #c3ccd8;
  line-height: 1.5;
}

.word-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 8px;
}

.word-form input {
  min-height: 54px;
  font-size: 20px;
}

.tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tools button,
.shop-list button {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.tools button:hover,
.shop-list button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(45, 212, 191, .08);
}

.shop-list button {
  min-height: 46px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.shop-list strong { color: var(--gold); }

.inventory {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

.inventory div { padding: 10px; }

.inventory strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
}

.history-head { margin-top: 8px; }

.rank-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.rank-tabs button {
  min-height: 34px;
  padding: 0 8px;
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.rank-tabs button.selected {
  background: var(--accent);
  color: #07110f;
}

.ranking-list {
  max-height: 260px;
  margin-bottom: 16px;
}

ol {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 470px;
  overflow: auto;
}

li {
  display: grid;
  gap: 4px;
  padding: 10px 11px;
}

li strong {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

li span {
  color: var(--muted);
  font-size: 12px;
}

.success { color: var(--accent) !important; }
.error { color: var(--red) !important; }
.warn { color: var(--gold) !important; }

@media (max-width: 1060px) {
  .layout { grid-template-columns: 1fr; }
  .game-board { min-height: 0; }
  ol { max-height: 320px; }
}

@media (max-width: 680px) {
  .shell {
    width: min(100% - 20px, 1240px);
    padding: 10px 0;
  }

  .hero,
  .game-top,
  .letter-stage {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .hero { padding: 16px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .word-form,
  .auth-actions,
  .compact-form,
  .stake-form,
  .match-strip {
    grid-template-columns: 1fr;
  }

  .letter-stage { min-height: 0; }
}
