:root {
  --bg: #FBF7F0;
  --bg-grain: #F6EFE2;
  --surface: #FFFFFF;
  --surface-warm: #FAF6EE;
  --ink: #2C2A33;
  --ink-soft: #6B6862;
  --line: #E8DCC8;
  --line-strong: #DDC9A8;

  --sage: #3D6B5A;
  --sage-deep: #2D5446;
  --coral: #E8826A;
  --coral-deep: #C9624C;
  --gold: #E6B453;
  --sand: #EFE3CC;
  --sand-deep: #E2D2B2;

  --n1: #3D6B5A;
  --n2: #C9842F;
  --n3: #C84B3C;
  --n4: #5B4A8A;
  --n5: #8B3A2E;
  --n6: #2E7D8B;
  --n7: #2C2A33;
  --n8: #6B6862;

  --shadow-soft: 0 1px 0 rgba(255,255,255,0.6) inset, 0 -1px 0 rgba(0,0,0,0.04) inset;
  --shadow-card: 0 1px 2px rgba(60,40,20,0.04), 0 12px 32px -16px rgba(60,40,20,0.16);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --easing: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Manrope', system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-feature-settings: 'ss01' on, 'cv11' on;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 8% 12%, rgba(232,130,106,0.10) 0, transparent 38%),
    radial-gradient(circle at 92% 88%, rgba(61,107,90,0.10) 0, transparent 42%),
    radial-gradient(circle at 60% 0%, rgba(230,180,83,0.08) 0, transparent 35%);
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 36px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* ----------- HERO ----------- */
.hero {
  position: relative;
  padding: 26px 28px 22px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.85), rgba(255,255,255,0.55)),
    linear-gradient(135deg, #F8EFDC 0%, #F0E2C5 100%);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.hero-mark {
  position: absolute;
  top: 18px;
  right: 22px;
  display: flex;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-a { background: var(--coral); }
.dot-b { background: var(--gold); }
.dot-c { background: var(--sage); }

.hero-title {
  font-family: 'Fraunces', 'Songti SC', serif;
  font-weight: 700;
  font-size: clamp(46px, 9vw, 64px);
  line-height: 0.95;
  margin: 0;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.hero-title em {
  font-style: italic;
  font-weight: 500;
  color: var(--coral-deep);
  font-variation-settings: 'opsz' 144, 'SOFT' 80;
}
.hero-sub {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 14.5px;
  letter-spacing: 0.01em;
}

/* ----------- PANEL ----------- */
.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(232,220,200,0.7);
}

/* tabs */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
  background: var(--bg-grain);
  padding: 6px;
  border-radius: var(--radius-md);
}
.tab {
  border: none;
  background: transparent;
  padding: 10px 6px 8px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tab span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  opacity: 0.7;
  font-weight: 500;
}
.tab:hover { color: var(--ink); }
.tab.is-active {
  background: var(--surface);
  color: var(--sage-deep);
  box-shadow: 0 1px 2px rgba(60,40,20,0.06), 0 4px 12px -4px rgba(60,40,20,0.08);
}
.tab.is-active span { color: var(--sage); opacity: 0.95; }

/* custom row */
.custom-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 10px;
  margin: -4px 0 16px;
  padding: 12px;
  background: var(--bg-grain);
  border-radius: var(--radius-md);
  align-items: end;
}
.custom-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}
.custom-row input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease;
}
.custom-row input:focus { border-color: var(--sage); }

.ghost-btn {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.ghost-btn:hover { background: var(--bg-grain); }
.ghost-btn:active { transform: translateY(1px); }

/* HUD */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: linear-gradient(180deg, #FBF4E2, #F4E8CB);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}
.hud-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.hud-cell:last-of-type { align-items: flex-end; }
.hud-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.hud-value {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 26px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.smiley {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background:
    radial-gradient(circle at 30% 25%, #FFE89A 0%, var(--gold) 70%, #C99932 100%);
  box-shadow:
    0 0 0 4px rgba(255,255,255,0.6),
    0 2px 4px rgba(60,40,20,0.12),
    inset 0 -3px 6px rgba(0,0,0,0.08);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 26px;
  transition: transform 0.18s var(--easing);
}
.smiley:hover { transform: scale(1.06); }
.smiley:active { transform: scale(0.94); }

.smiley-face {
  line-height: 1;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,0.5));
}

/* flag toggle */
.flag-toggle {
  margin: 0 0 16px;
}
.flag-btn {
  width: 100%;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-grain);
  border: 1px dashed var(--line-strong);
  transition: all 0.2s ease;
}
.flag-btn .flag-ico {
  font-size: 18px;
  color: var(--ink-soft);
  transition: color 0.2s ease;
}
.flag-btn .flag-label {
  font-weight: 700;
}
.flag-btn .flag-hint {
  font-size: 11.5px;
  color: var(--ink-soft);
  text-align: right;
  line-height: 1.3;
}
.flag-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, #FFE6DE, #FBD2C2);
  border-style: solid;
  border-color: var(--coral);
  color: var(--coral-deep);
}
.flag-btn[aria-pressed="true"] .flag-ico {
  color: var(--coral-deep);
}
.flag-btn[aria-pressed="true"] .flag-hint {
  color: var(--coral-deep);
  opacity: 0.85;
}

/* ----------- BOARD ----------- */
.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 8px;
  background: var(--bg-grain);
  border-radius: var(--radius-md);
  overflow: auto;
}
.board {
  display: grid;
  gap: 3px;
  padding: 6px;
  background: var(--sand-deep);
  border-radius: 10px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  --size: 34px;
  width: var(--size);
  height: var(--size);
  border-radius: 6px;
  border: none;
  padding: 0;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: calc(var(--size) * 0.5);
  cursor: pointer;
  position: relative;
  background:
    linear-gradient(155deg, #F4E9D2 0%, #E8DCC2 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.7),
    inset 0 -1px 2px rgba(0,0,0,0.06);
  color: transparent;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}
.cell:hover:not(.is-revealed):not(.is-flagged) {
  background: linear-gradient(155deg, #F8EFDC 0%, #EFE3C8 100%);
  transform: translateY(-1px);
}
.cell:active:not(.is-revealed) { transform: translateY(0); }

.cell.is-revealed {
  background: var(--surface-warm);
  box-shadow:
    inset 0 0 0 1px rgba(220,200,170,0.5);
  cursor: default;
  animation: reveal 0.32s var(--easing);
}
.cell.is-revealed.is-empty { color: transparent; }
.cell.is-revealed[data-n="1"] { color: var(--n1); }
.cell.is-revealed[data-n="2"] { color: var(--n2); }
.cell.is-revealed[data-n="3"] { color: var(--n3); }
.cell.is-revealed[data-n="4"] { color: var(--n4); }
.cell.is-revealed[data-n="5"] { color: var(--n5); }
.cell.is-revealed[data-n="6"] { color: var(--n6); }
.cell.is-revealed[data-n="7"] { color: var(--n7); }
.cell.is-revealed[data-n="8"] { color: var(--n8); }

.cell.is-flagged {
  background: linear-gradient(155deg, #FFD9CB 0%, #F2B59C 100%);
}
.cell.is-flagged::before {
  content: '⚑';
  color: var(--coral-deep);
  font-size: calc(var(--size) * 0.55);
  line-height: 1;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,0.6));
}

.cell.is-mine {
  background: radial-gradient(circle at 50% 50%, #FFB199 0%, var(--coral) 60%, var(--coral-deep) 100%);
  animation: boom 0.45s ease;
}
.cell.is-mine::before {
  content: '●';
  color: #2C2A33;
  font-size: calc(var(--size) * 0.55);
}
.cell.is-mine-trigger {
  background: radial-gradient(circle at 50% 50%, #FF8E70 0%, #D94627 80%);
  box-shadow: 0 0 0 2px #B23018;
}
.cell.is-wrong-flag {
  background: var(--surface-warm);
}
.cell.is-wrong-flag::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--size) * 0.7);
  color: #B23018;
  font-weight: 900;
}

@keyframes reveal {
  0%   { transform: scale(0.6); }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes boom {
  0%   { transform: scale(0.85); }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(251,247,240,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: var(--radius-md);
  animation: fadeIn 0.25s ease;
}
.overlay-card {
  background: var(--surface);
  padding: 22px 26px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  text-align: center;
  max-width: 280px;
  border: 1px solid var(--line);
}
.overlay-ico { font-size: 38px; line-height: 1; margin-bottom: 6px; }
.overlay h2 {
  margin: 6px 0 4px;
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.01em;
}
.overlay p {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 13.5px;
}
.primary-btn {
  border: none;
  background: linear-gradient(180deg, var(--sage) 0%, var(--sage-deep) 100%);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  padding: 10px 22px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 14px -4px rgba(45,84,70,0.5);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px -4px rgba(45,84,70,0.55); }
.primary-btn:active { transform: translateY(0); }

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.overlay-actions .ghost-btn {
  font-size: 13px;
  padding: 8px 14px;
}
.text-link {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 4px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-link:hover { color: var(--ink); }

/* ----------- START SCREEN ----------- */
.start-screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(180deg, rgba(251,247,240,0.96), rgba(248,239,220,0.92));
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border-radius: var(--radius-md);
  z-index: 5;
  animation: fadeIn 0.3s ease;
}
.start-card {
  width: 100%;
  max-width: 480px;
  text-align: center;
}
.start-title {
  font-family: 'Fraunces', 'Songti SC', serif;
  font-weight: 700;
  font-size: clamp(22px, 5vw, 28px);
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 6px;
}
.start-sub {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 0 0 18px;
  letter-spacing: 0.01em;
}
.start-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.diff-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  transition: transform 0.2s var(--easing), box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.diff-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px -10px rgba(60,40,20,0.20);
}
.diff-card:active { transform: translateY(0); }
.diff-emoji { font-size: 24px; line-height: 1; margin-bottom: 2px; }
.diff-name {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
}
.diff-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}
.diff-tag {
  font-size: 11px;
  color: var(--sage);
  background: rgba(61,107,90,0.10);
  border-radius: 999px;
  padding: 2px 9px;
  margin-top: 6px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.diff-card[data-level="beginner"]:hover  { border-color: var(--sage); background: #F6FBF7; }
.diff-card[data-level="intermediate"]:hover { border-color: var(--gold); background: #FBF6E7; }
.diff-card[data-level="intermediate"] .diff-tag { color: #B0791F; background: rgba(201,132,47,0.12); }
.diff-card[data-level="expert"]:hover { border-color: var(--coral); background: #FCF1ED; }
.diff-card[data-level="expert"] .diff-tag { color: var(--coral-deep); background: rgba(232,130,106,0.14); }
.diff-card[data-level="custom"]:hover { border-color: var(--n4); background: #F6F3FA; }
.diff-card[data-level="custom"] .diff-tag { color: var(--n4); background: rgba(91,74,138,0.10); }


@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to   { opacity: 1; transform: scale(1); }
}

/* ----------- RECORDS ----------- */
.records {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 22px 20px;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(232,220,200,0.7);
}
.records h3 {
  margin: 0 0 12px;
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.records-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.record-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg-grain);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
}
.record-name {
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
}
.record-time {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 22px;
  color: var(--sage-deep);
  font-variant-numeric: tabular-nums;
}
.records-note {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ----------- FOOTER ----------- */
.foot {
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
}
.foot details {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  padding: 12px 18px;
  text-align: left;
}
.foot summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.foot summary::after {
  content: '＋';
  color: var(--sage);
  transition: transform 0.2s ease;
}
.foot details[open] summary::after { content: '−'; }
.foot ul {
  margin: 12px 0 0;
  padding-left: 18px;
  line-height: 1.7;
}
.foot li { margin: 2px 0; }

/* ----------- SHARE MODAL ----------- */
.share-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fadeIn 0.22s ease;
}
.share-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 42, 51, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.share-sheet {
  position: relative;
  width: min(420px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 18px 20px;
  box-shadow: 0 24px 60px -12px rgba(44,42,51,0.4);
  animation: sheetUp 0.32s var(--easing);
}
@keyframes sheetUp {
  from { opacity: 0; transform: translateY(28px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.share-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg-grain);
  color: var(--ink-soft);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background 0.15s ease, color 0.15s ease;
}
.share-close:hover { background: var(--sand-deep); color: var(--ink); }

.share-preview {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-grain);
  margin-bottom: 14px;
  min-height: 100px;
}
#sharePreview {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: default;
  touch-action: manipulation;
}
#shareCanvas { display: block; }
#shareCanvas[hidden] { display: none !important; }

.share-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.share-actions .primary-btn,
.share-actions .ghost-btn {
  width: 100%;
  font-size: 14px;
  padding: 11px 14px;
}
.primary-btn.alt {
  background: linear-gradient(180deg, #B2917A 0%, #8E6E58 100%);
  box-shadow: 0 4px 14px -4px rgba(110,80,50,0.45);
}
.primary-btn.alt:hover { box-shadow: 0 6px 18px -4px rgba(110,80,50,0.55); }
.share-tip {
  margin: 0 2px 12px;
  font-size: 12.5px;
  color: var(--coral-deep);
  text-align: center;
  line-height: 1.5;
  font-weight: 600;
}
.share-tip-top {
  background: linear-gradient(180deg, #FFE6DE, #FBD2C2);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 4px 0 12px;
}

/* mobile tuning */
@media (max-width: 560px) {
  .page { padding: 18px 12px 60px; gap: 18px; }
  .hero { padding: 22px 22px 18px; }
  .panel { padding: 16px 14px; }
  .tabs { gap: 4px; padding: 4px; }
  .tab { padding: 9px 3px 7px; font-size: 13px; }
  .tab span { font-size: 10px; }
  .hud { padding: 12px 14px; }
  .hud-value { font-size: 22px; }
  .smiley { width: 46px; height: 46px; font-size: 22px; }
  .flag-btn { grid-template-columns: auto 1fr; }
  .flag-btn .flag-hint { display: none; }
  .records-grid { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .record-card { padding: 10px; }
  .record-time { font-size: 18px; }
}
