:root {
  --bg: #f6f7f2;
  --ink: #181c20;
  --muted: #66706b;
  --line: #d9ded6;
  --panel: #ffffff;
  --panel-2: #edf3ed;
  --green: #237b4b;
  --green-2: #1d6a40;
  --blue: #245f8f;
  --red: #b23b3b;
  --yellow: #e4ad35;
  --shadow: 0 18px 46px rgba(29, 43, 35, 0.12);
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, textarea, select { font: inherit; }

button {
  border: 0;
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(14px, 4vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 242, 0.92);
  backdrop-filter: blur(16px);
}

.brand {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.brand strong {
  font-size: 1.05rem;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand small {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions, .row, .button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.top-actions { justify-content: flex-end; }

.menu-button,
.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  font-weight: 900;
}

.menu-button {
  gap: 4px;
  align-content: center;
}

.menu-button span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  background: rgba(24, 28, 32, 0.24);
}

.drawer-backdrop.show {
  display: block;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 31;
  width: min(340px, calc(100vw - 28px));
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 52px rgba(24, 28, 32, 0.18);
  transform: translateX(105%);
  transition: transform 180ms ease;
}

.drawer.show {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-head strong,
.drawer-head small {
  display: block;
}

.drawer-head small {
  margin-top: 2px;
  color: var(--muted);
}

.drawer-nav {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
}

.drawer-nav button {
  min-height: 48px;
  padding: 12px 14px;
  text-align: left;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-weight: 900;
}

.drawer-nav button:hover,
.drawer-nav button.active {
  background: var(--panel-2);
  border-color: var(--line);
}

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

.auth-tabs button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  font-weight: 900;
  font-size: 0.86rem;
}

.auth-tabs button.active {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.auth-panel {
  display: none;
}

.auth-panel.active {
  display: block;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.pill strong {
  color: var(--ink);
  margin-left: 6px;
  letter-spacing: 0.08em;
}

.btn {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 9px 13px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 800;
  box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset;
}

.btn:hover { border-color: #b8c1b8; }
.btn.primary { background: var(--green); color: white; border-color: var(--green); }
.btn.primary:hover { background: var(--green-2); }
.btn.blue { background: var(--blue); color: white; border-color: var(--blue); }
.btn.red { background: #fff5f5; color: var(--red); border-color: #efc4c4; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

main {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 4vw, 34px);
}

#pagePortal.active {
  min-height: calc(100vh - 80px);
  display: grid;
  place-items: center;
}

.page { display: none; }
.page.active { display: block; }

.hero {
  min-height: calc(100vh - 90px);
  place-items: center;
}

.hero.active { display: grid; }

.login-grid {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(18px, 4vw, 42px);
  align-items: center;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 14px;
  font-size: clamp(2.45rem, 7vw, 5.4rem);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.15rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.page-title {
  font-size: clamp(2rem, 5vw, 4rem);
}

.lead {
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.55;
  max-width: 60ch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 24px);
}

.panel + .panel { margin-top: 16px; }

label {
  display: block;
  color: #3e4843;
  font-weight: 800;
  margin: 12px 0 6px;
}

input, textarea, select {
  width: 100%;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid #cbd2ca;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.45;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(35, 123, 75, 0.14);
}

.note {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.stack {
  display: grid;
  gap: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.grid-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.play-layout {
  display: block;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  width: min(760px, 100%);
  margin: 0 auto;
}

.app-tile {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 168px;
  padding: clamp(18px, 4vw, 28px);
  text-align: left;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.app-tile-large {
  min-height: 280px;
}

.app-tile-kicker {
  color: var(--green);
  font-weight: 900;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.app-tile strong {
  font-size: clamp(3rem, 8vw, 5.8rem);
  line-height: 0.94;
}

.app-tile span:last-child {
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.45;
  max-width: 42ch;
}

.app-tile:hover,
.choice-card:hover {
  border-color: #aeb9ae;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.choice-card {
  min-height: 104px;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 16px;
  text-align: left;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.choice-card strong {
  font-size: 1rem;
}

.choice-card span {
  color: var(--muted);
  line-height: 1.35;
}

.choice-card.active {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(35, 123, 75, 0.12);
}

.lobby-panel {
  display: none;
}

.lobby-panel.active {
  display: block;
}

.settings-game {
  margin-top: 18px;
}

.settings-block {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

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

.game-card, .player, .phrase {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 12px;
}

.game-card {
  display: grid;
  gap: 10px;
}

.game-card-head, .split {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.meta {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.role {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #eef5ff;
  color: #17456c;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.role.owner {
  background: #fff6d8;
  color: #75520a;
}

.board-tools {
  display: grid;
  gap: 12px;
}

.score-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.score {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 12px;
  min-width: 0;
}

.score span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.score strong {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
}

.board {
  display: grid;
  gap: 8px;
  width: min(680px, 100%);
  margin: 0 auto;
  aspect-ratio: 1;
  min-height: min(680px, calc(100vw - 68px));
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius);
  border: 1px solid #cbd2ca;
  background: #fff;
  color: var(--ink);
  padding: clamp(4px, 1.1vw, 10px);
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.18;
  font-size: clamp(0.66rem, 1.25vw, 0.95rem);
  overflow: hidden;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.cell:hover { border-color: #9ea99e; }
.cell.active { background: #dff1e5; border-color: var(--green); }
.cell.free { background: #f9edd0; border-color: var(--yellow); font-weight: 900; }
.cell.win { background: #237b4b; border-color: #237b4b; color: white; }

.cell span {
  position: relative;
  z-index: 1;
}

.mark-strip {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  justify-content: center;
  gap: 4px;
  pointer-events: none;
}

.mark-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.86);
  box-shadow: 0 1px 3px rgba(0,0,0,0.22);
}

.empty {
  min-height: 190px;
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed #c3cbc2;
  border-radius: var(--radius);
  background: #fbfcf9;
}

.phrase {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.phrase button {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: #fff5f5;
  color: var(--red);
  border: 1px solid #efc4c4;
  font-weight: 900;
}

.player {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.player-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.player-color {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--player-color);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.06);
  flex: 0 0 auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(20px);
  z-index: 40;
  min-width: min(420px, calc(100vw - 28px));
  max-width: calc(100vw - 28px);
  padding: 12px 14px;
  background: #18201b;
  color: white;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  font-weight: 800;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(15, 20, 17, 0.48);
}

.modal-backdrop.show { display: grid; }

.modal {
  width: min(440px, 100%);
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0,0,0,0.28);
  padding: 24px;
  text-align: center;
}

.modal-buttons {
  justify-content: center;
}

.hidden { display: none !important; }

@media (max-width: 920px) {
  .login-grid, .grid-main, .grid-2, .choice-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  main { padding: 14px; }
  .score-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .score { padding: 9px; }
  .score strong { font-size: 1.05rem; }
  .board { gap: 5px; }
  .cell { font-size: clamp(0.58rem, 2.5vw, 0.78rem); }
  .button-row .btn { flex: 1 1 auto; }
  .top-actions .pill { width: auto; justify-content: center; }
  .auth-tabs { grid-template-columns: 1fr; }
}
