:root {
  --paper: #edf3ef;
  --ink: #172522;
  --ink-soft: #5b6d67;
  --glass: rgba(255, 255, 255, 0.56);
  --glass-strong: rgba(255, 255, 255, 0.78);
  --line: rgba(42, 74, 66, 0.16);
  --mist: #c8dbd3;
  --jade: #3f8a78;
  --tea: #9b7b43;
  --cinnabar: #d84032;
  --indigo: #334e68;
  --shadow: 0 24px 80px rgba(30, 59, 52, 0.18);
  color-scheme: light;
  font-family: Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(220, 232, 226, 0.95), transparent 34%),
    linear-gradient(135deg, #f7faf8 0%, var(--paper) 48%, #dfeae5 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 22px;
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px;
}

.game-panel,
.side-panel .module,
.stats-grid,
.map-glass {
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.2);
}

.game-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: calc(100vh - 44px);
  overflow: hidden;
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 14px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 4px;
  color: var(--jade);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: clamp(30px, 4vw, 56px);
  font-weight: 700;
  line-height: 0.95;
}

h2 {
  font-size: 16px;
  font-weight: 750;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.66);
}

.map-wrap {
  position: relative;
  display: grid;
  min-height: 0;
  padding: 18px;
  place-items: center;
}

#gameCanvas {
  width: min(100%, calc(100vh - 138px));
  max-height: calc(100vh - 138px);
  aspect-ratio: 1;
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(253, 255, 252, 0.84), rgba(222, 236, 229, 0.72));
  box-shadow: inset 0 0 0 1px rgba(41, 75, 68, 0.08), 0 18px 60px rgba(30, 61, 54, 0.12);
  touch-action: none;
}

.map-glass {
  position: absolute;
  right: 32px;
  bottom: 32px;
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: calc(100% - 64px);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}

.map-glass span:first-child {
  color: var(--ink);
  font-weight: 750;
}

.mobile-pad {
  position: absolute;
  left: 28px;
  bottom: 28px;
  display: none;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(2, 46px);
  gap: 6px;
}

.mobile-pad button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-strong);
}

.mobile-pad [data-turn="up"] {
  grid-column: 2;
}

.mobile-pad [data-turn="left"] {
  grid-column: 1;
  grid-row: 2;
}

.mobile-pad [data-turn="right"] {
  grid-column: 3;
  grid-row: 2;
}

.mobile-pad [data-turn="down"] {
  grid-column: 2;
  grid-row: 2;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: calc(100vh - 44px);
  overflow-y: auto;
  padding-right: 2px;
}

.module {
  padding: 16px;
  border-radius: 8px;
}

.module-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.module-head span {
  color: var(--ink-soft);
  font-size: 12px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 12px;
}

.field input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  outline: none;
}

.field input:focus,
button:focus-visible {
  outline: 2px solid rgba(216, 64, 50, 0.34);
  outline-offset: 2px;
}

.spawn-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.spawn-grid button,
.room-row button,
.primary {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.66);
}

.spawn-grid button {
  min-height: 38px;
}

.spawn-grid button.active {
  color: #fff;
  border-color: transparent;
  background: var(--jade);
}

.primary {
  width: 100%;
  height: 42px;
  color: #fff;
  border: 0;
  background: var(--cinnabar);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border-radius: 8px;
}

.stat {
  padding: 12px;
  background: rgba(255, 255, 255, 0.38);
}

.stat span {
  display: block;
  color: var(--ink-soft);
  font-size: 12px;
}

.stat strong {
  font-size: 26px;
  line-height: 1.1;
}

.now-bean {
  min-height: 44px;
  border: 1px solid rgba(63, 138, 120, 0.18);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.42);
  font-weight: 720;
}

.log-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 82px;
  overflow: auto;
  margin-top: 10px;
}

.log-list span {
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.58);
  font-size: 12px;
}

.card-rack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.dialect-card {
  min-height: 82px;
  border: 1px solid rgba(23, 37, 34, 0.1);
  border-radius: 8px;
  padding: 10px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.2)),
    repeating-linear-gradient(160deg, rgba(63, 138, 120, 0.12), rgba(63, 138, 120, 0.12) 1px, transparent 1px, transparent 9px);
}

.dialect-card.locked {
  color: rgba(23, 37, 34, 0.36);
  filter: grayscale(0.8);
}

.dialect-card strong {
  display: block;
  margin-bottom: 6px;
}

.dialect-card span {
  color: var(--ink-soft);
  font-size: 12px;
}

.leaderboard {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.leaderboard li {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.leaderboard strong {
  display: block;
}

.leaderboard span {
  color: var(--ink-soft);
  font-size: 12px;
}

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

.room-row code {
  display: grid;
  min-width: 0;
  min-height: 38px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.46);
  text-overflow: ellipsis;
}

@media (max-width: 1120px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .game-panel,
  .side-panel {
    min-height: auto;
  }

  #gameCanvas {
    width: min(100%, 760px);
    max-height: none;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 10px;
  }

  .topbar {
    padding: 16px;
  }

  .map-wrap {
    padding: 10px;
  }

  .map-glass {
    right: 18px;
    bottom: 18px;
  }

  .mobile-pad {
    display: grid;
  }

  .spawn-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
