:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --ink: #20242a;
  --muted: #69707a;
  --line: #d9d2c7;
  --panel: #fffaf1;
  --paper: #ffffff;
  --accent: #e14f3d;
  --accent-2: #2f8c70;
  --accent-3: #3f6fb5;
  --warn: #f2b84b;
  --bad: #b83b45;
  --shadow: 0 18px 50px rgba(41, 35, 26, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 22px 22px;
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 700;
}

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

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 24px;
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.resource-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.resource-strip span {
  min-width: 88px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-align: center;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  margin: 22px 0;
}

.tab,
.ghost-btn,
.primary-btn,
.items button,
.file-picker span {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 0 16px;
}

.tab.active,
.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.panel {
  display: none;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.86);
  box-shadow: var(--shadow);
}

.panel.active {
  display: block;
}

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title p,
.hint-text,
.game-meta,
#gameMeta {
  color: var(--muted);
}

.level-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.level-card,
.work-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  overflow: hidden;
}

.level-preview,
.work-preview {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  padding: 12px;
  background: #f8f5ef;
}

.mini-cell {
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.level-info,
.work-info {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.level-info button,
.work-info button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: var(--accent-3);
  color: #fff;
  font-weight: 700;
}

.free-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.free-tools label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.file-picker input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.file-picker span {
  display: inline-flex;
  align-items: center;
}

select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 0 12px;
}

.hint-text {
  margin-top: 14px;
}

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

.game-head {
  margin-bottom: 14px;
}

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

.board-wrap {
  width: 100%;
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #efe7d8;
  overflow: auto;
}

.board {
  display: grid;
  width: min(72vh, 100%);
  max-width: 720px;
  min-width: min(100%, 330px);
  aspect-ratio: 1;
  border: 2px solid #342e27;
  background: #fff;
  touch-action: manipulation;
}

.cell {
  position: relative;
  border: 1px solid rgba(31, 34, 39, 0.08);
  background: #fbfbfb;
  padding: 0;
}

.cell.outline::after {
  content: "";
  position: absolute;
  inset: 22%;
  border: 1px solid rgba(20, 20, 20, 0.42);
  border-radius: 50%;
}

.cell.correct {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.cell.wrong {
  animation: shake 0.18s linear 2;
  box-shadow: inset 0 0 0 2px var(--bad);
}

.cell.hint {
  outline: 2px solid var(--warn);
  z-index: 1;
}

@keyframes shake {
  0% { transform: translateX(0); }
  50% { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

.side-panel {
  display: grid;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.reference-preview {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  max-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(-45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%) 0 8px / 16px 16px,
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%) 8px -8px / 16px 16px,
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%) 0 0 / 16px 16px,
    #fff;
}

.reference-preview .mini-cell {
  border-color: rgba(0, 0, 0, 0.06);
}

.palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.swatch.active {
  border-color: var(--ink);
  transform: translateY(-2px);
}

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

.items button {
  padding: 0 8px;
}

.works-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.result-dialog {
  width: min(420px, calc(100vw - 34px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.result-dialog::backdrop {
  background: rgba(20, 17, 12, 0.38);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 820px) {
  .top-bar,
  .section-title,
  .game-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

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

  .level-list,
  .works-list {
    grid-template-columns: 1fr;
  }

  .board-wrap {
    min-height: 330px;
    padding: 8px;
  }

  .board {
    min-width: 292px;
  }
}
