/* ===================== reset & base ===================== */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
               "Source Han Serif SC", "Songti SC", serif;
  color: #2C2C2C;
  background: #F5E6C8;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior: contain;
  touch-action: none;
}
body {
  min-height: 100dvh;
  background: linear-gradient(180deg, #FAF1DC 0%, #F5E6C8 50%, #E8D5A8 100%);
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: #6B6B6B; font-size: 14px; letter-spacing: 1px; }

/* ===================== screen system ===================== */
.screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.screen.active { display: flex; }

/* ===================== splash ===================== */
.splash-inner {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 24px;
  gap: 18px;
}
.title-frame {
  border: 1.5px solid #2C2C2C;
  padding: 22px 32px;
  background: rgba(255, 255, 255, 0.15);
}
.title {
  font-size: 36px;
  letter-spacing: 12px;
  font-weight: 600;
  margin: 0;
  text-indent: 12px; /* compensate trailing letter-spacing */
}
.subtitle {
  font-size: 15px;
  letter-spacing: 4px;
  color: #4A4A4A;
  margin: 6px 0 0;
}
.splash-actions {
  margin-top: 36px;
  display: flex; flex-direction: column; gap: 12px;
  align-items: stretch; min-width: 220px;
}
.about {
  margin-top: 28px; max-width: 320px;
  background: rgba(255, 255, 255, 0.4);
  border-left: 3px solid #C9A86A;
  padding: 14px 16px;
  font-size: 14px; line-height: 1.7;
  letter-spacing: 0.5px;
}
.about p { margin: 0 0 8px; }
.about p:last-child { margin: 0; }

/* ===================== buttons ===================== */
.ink-btn {
  background: #2C2C2C;
  color: #F5E6C8;
  border: none;
  padding: 14px 28px;
  border-radius: 32px;
  font-size: 17px;
  letter-spacing: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.ink-btn:active { transform: translateY(1px); box-shadow: 0 2px 8px rgba(0,0,0,0.18); }

.ghost-btn {
  background: rgba(201, 168, 106, 0.2);
  color: #2C2C2C;
  border: 1px solid #C9A86A;
  padding: 12px 24px;
  border-radius: 32px;
  font-size: 15px;
  letter-spacing: 3px;
}
.ghost-btn.small {
  padding: 6px 14px;
  font-size: 13px;
  letter-spacing: 2px;
  border-radius: 20px;
}
.ghost-btn:active { background: rgba(201, 168, 106, 0.4); }

.back-btn {
  background: transparent; border: none;
  font-size: 28px; line-height: 1;
  padding: 8px 14px;
  color: #2C2C2C;
}
.back-btn:active { color: #B8312F; }

/* ===================== topbar ===================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(44, 44, 44, 0.12);
  background: rgba(255, 255, 255, 0.25);
}
.topbar h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 6px;
  font-weight: 500;
}
.topbar-spacer { width: 52px; } /* matches back-btn width */

/* ===================== levels list ===================== */
.levels-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.chapter {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 0 8px;
}
.chapter-bar {
  width: 4px; height: 18px; background: #C9A86A;
}
.chapter-name {
  font-size: 14px; letter-spacing: 3px; color: #4A4A4A;
}
.level-card {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  margin-bottom: 8px;
  border: 1px solid rgba(44, 44, 44, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.35);
  text-align: left;
}
.level-card.locked {
  opacity: 0.45;
  background: rgba(0, 0, 0, 0.04);
  cursor: not-allowed;
}
.level-card.cleared { background: rgba(201, 168, 106, 0.15); }
.level-info { flex: 1; }
.level-title {
  font-size: 17px; letter-spacing: 2px; font-weight: 500; margin: 0 0 4px;
}
.level-author {
  font-size: 13px; color: #6B6B6B; letter-spacing: 1px;
}
.level-stars { font-size: 16px; letter-spacing: 2px; color: #C9A86A; }
.level-stars .empty { color: rgba(0, 0, 0, 0.18); }

/* ===================== game ===================== */
.hint-area {
  padding: 10px 16px 6px;
}
.hint-meta {
  font-size: 13px; color: #4A4A4A; letter-spacing: 1px; margin-bottom: 6px;
}
.hint-lines {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 16px; letter-spacing: 4px;
}
.hint-line {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 0;
}
.hint-line .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
}
.hint-line.found .dot { background: #C9A86A; }
.hint-line.found .text { color: #2C2C2C; }
.hint-line .text {
  color: rgba(0, 0, 0, 0.35);
  font-weight: 500;
}
.hint-line:not(.found) .text {
  letter-spacing: 6px;
}

.grid-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 6px 12px 12px;
  min-height: 0;
}
.grid-container {
  position: relative;
  width: 100%;
  max-width: min(96vw, calc(100dvh - 320px));
  aspect-ratio: var(--grid-aspect, 1);
}
.grid {
  display: grid;
  width: 100%; height: 100%;
  grid-template-columns: repeat(var(--cols, 5), 1fr);
  grid-template-rows: repeat(var(--rows, 5), 1fr);
  gap: 4px;
}
.cell {
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid rgba(44, 44, 44, 0.15);
  border-radius: 6px;
  font-size: clamp(16px, 5vw, 26px);
  color: #2C2C2C;
  font-weight: 500;
  letter-spacing: 0;
  user-select: none;
  -webkit-user-select: none;
  transition: background 80ms ease, transform 80ms ease;
}
.cell.found {
  background: rgba(201, 168, 106, 0.35);
  border-color: #C9A86A;
  color: #2C2C2C;
}
.cell.active {
  background: #2C2C2C;
  color: #F5E6C8;
  transform: scale(0.94);
}
.trail {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.trail polyline {
  fill: none;
  stroke: #2C2C2C;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
}
.trail polyline.persistent {
  stroke: #C9A86A;
  stroke-width: 5;
  opacity: 0.6;
}

.feedback {
  min-height: 26px;
  text-align: center;
  font-size: 14px;
  letter-spacing: 2px;
  color: #6B6B6B;
  padding: 0 16px 6px;
}
.feedback.success { color: #C9A86A; }
.feedback.error { color: #B8312F; }

/* ===================== victory ===================== */
.victory-inner {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 32px 24px 20px;
  gap: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.seal {
  display: inline-block;
  padding: 10px 18px;
  background: #B8312F;
  color: #F5E6C8;
  font-size: 18px;
  letter-spacing: 8px;
  font-weight: 600;
  margin-bottom: 8px;
}
#victory-title {
  font-size: 26px; letter-spacing: 4px; font-weight: 600; margin: 0;
}
.poem-card {
  margin: 8px 0;
  padding: 18px 22px;
  border: 1px solid rgba(44, 44, 44, 0.2);
  background: rgba(255, 255, 255, 0.4);
  display: flex; flex-direction: column; gap: 6px;
}
.poem-card .verse {
  font-size: 19px;
  letter-spacing: 5px;
  font-weight: 500;
  text-align: center;
}
.translation, .background-text {
  font-size: 14px; line-height: 1.8;
  letter-spacing: 1px;
  color: #4A4A4A;
  max-width: 520px;
  text-align: justify;
}
.background-text { font-size: 13px; color: #6B6B6B; }
.victory-actions {
  margin-top: 20px;
  display: flex; flex-direction: column; gap: 10px;
  align-items: stretch; min-width: 220px;
}

/* ===================== misc responsive ===================== */
@media (min-height: 800px) {
  .grid-container { max-width: min(92vw, calc(100dvh - 360px)); }
}
@media (min-width: 600px) {
  .grid-container { max-width: 480px; }
}
