:root {
  --bg: #f3f5ee;
  --ink: #101514;
  --muted: #66706b;
  --soft: #dfe5d8;
  --line: #c4cec0;
  --panel: rgba(255, 255, 255, 0.78);
  --jade: #147767;
  --terra: #bd5d38;
  --amber: #d49a26;
  --shadow: 0 22px 60px rgba(16, 21, 20, 0.12);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, #111917 0 18px, var(--jade) 18px 24px, transparent 24px),
    radial-gradient(circle at 82% 12%, rgba(46, 96, 143, 0.08), transparent 26%),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app {
  width: min(1440px, calc(100vw - 34px));
  margin: 0 auto;
  padding: 28px 0 30px 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 0 22px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 70px);
  line-height: 0.9;
  letter-spacing: 0;
}

.topbar p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
}

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

.user-badge {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.command-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 18px;
  font-weight: 850;
  cursor: pointer;
}

.command-button:hover,
.match-list button:hover {
  border-color: #8fa094;
  transform: translateY(-1px);
}

.command-button.wide {
  width: 100%;
  margin-top: 12px;
}

.auth-layout,
.lobby-layout,
.game-layout {
  display: grid;
  gap: 22px;
  align-items: start;
}

.auth-layout {
  grid-template-columns: repeat(2, minmax(280px, 1fr));
}

.lobby-layout {
  grid-template-columns: 330px minmax(320px, 1fr) minmax(260px, 0.7fr);
  margin-bottom: 22px;
}

.game-layout {
  grid-template-columns: minmax(560px, 1fr) 360px;
}

.auth-panel,
.create-panel,
.list-panel,
.side-panel section {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 18px;
}

.auth-panel h2,
.create-panel h2,
.list-panel h2 {
  margin: 0 0 16px;
  font-size: 22px;
}

.auth-panel,
.create-panel {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

input,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 15px;
}

.match-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.match-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--soft);
  padding: 10px 0;
}

.match-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.match-list button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 0 12px;
  font-weight: 850;
  cursor: pointer;
}

.empty-row {
  color: var(--muted);
  font-size: 13px;
}

.board-area {
  min-width: 0;
}

.score-strip {
  display: grid;
  grid-template-columns: 170px minmax(180px, 1fr) 170px;
  align-items: center;
  gap: 14px;
  margin: 0 0 14px;
}

.player-score {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-left: 4px solid currentColor;
  padding: 6px 0 6px 12px;
}

.player-score.jade {
  color: var(--jade);
}

.player-score.terra {
  color: var(--terra);
}

.player-name {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.player-score strong {
  font-size: 32px;
  line-height: 1;
}

.score-track {
  position: relative;
  height: 14px;
  overflow: hidden;
  background: var(--soft);
}

.score-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  height: 100%;
  transition: width 180ms linear;
}

.score-fill.jade {
  background: var(--jade);
}

.score-fill.terra {
  left: auto;
  right: 0;
  background: var(--terra);
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  width: min(100%, calc(100vh - 220px));
  min-width: 560px;
  margin: 0 auto;
  background: #fbfcf8;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  touch-action: manipulation;
  cursor: crosshair;
}

.winner {
  position: absolute;
  left: 50%;
  top: 28px;
  transform: translateX(-50%);
  min-width: min(540px, calc(100% - 40px));
  padding: 16px 22px;
  background: var(--ink);
  color: #fff;
  text-align: center;
  font-size: 18px;
  font-weight: 850;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.18);
}

.side-panel {
  display: grid;
  gap: 12px;
}

.section-title {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.resource-row,
.stone-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.resource-row span,
.hint-line {
  color: var(--muted);
  font-size: 13px;
}

.resource-row strong {
  font-size: 34px;
  line-height: 1;
}

.cooldown-bar {
  height: 12px;
  margin: 14px 0 8px;
  background: var(--soft);
}

#cooldownFill {
  width: 0%;
  height: 100%;
  background: var(--amber);
  transition: width 120ms linear;
}

.stone-row {
  padding: 10px 0;
  border-top: 1px solid var(--soft);
}

.stone-row:first-of-type {
  border-top: 0;
}

.stone-row span:nth-child(2) {
  flex: 1;
  font-weight: 850;
}

.stone-row strong {
  color: var(--muted);
  font-size: 12px;
}

.stone-dot {
  display: inline-block;
  border-radius: 50%;
}

.stone-dot.small {
  width: 14px;
  height: 14px;
  background: var(--ink);
}

.stone-dot.medium {
  width: 22px;
  height: 22px;
  background: var(--jade);
}

.stone-dot.large {
  width: 30px;
  height: 30px;
  background: var(--terra);
}

.group-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}

.group-stats div {
  border-top: 1px solid var(--soft);
  padding-top: 10px;
}

.group-stats dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.group-stats dd {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 850;
}

.event-log {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding: 0 0 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.event-log li::marker {
  color: var(--amber);
  font-weight: 850;
}

.hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .auth-layout,
  .lobby-layout,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .canvas-wrap {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 720px) {
  body {
    background:
      linear-gradient(90deg, #111917 0 10px, var(--jade) 10px 14px, transparent 14px),
      var(--bg);
  }

  .app {
    width: min(100vw - 20px, 640px);
    padding-left: 10px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .score-strip,
  .side-panel {
    grid-template-columns: 1fr;
  }
}
