/* ============================================================
   Campo Minato - Main stylesheet
   campominato.com - vanilla CSS, no dependencies.

   Structure:
   1.  Design tokens (grayscale + semantic, light/dark)
   2.  Base reset & typography
   3.  Layout containers
   4.  Header & navigation
   5.  Footer
   6.  Buttons & forms
   7.  Cards & grids
   8.  Tables
   9.  Article typography (guide/blog pages)
   10. Game widget & board
   11. Demo boards (static examples)
   12. Cookie consent banner
   13. Test banner (zh-cn staging pages)
   14. Utilities & responsive
   ============================================================ */

/* ------------------------------------------------------------
   1. DESIGN TOKENS
   Grayscale ramp + semantic aliases. Dark mode overrides live
   under [data-theme="dark"]; the bootstrap script in <head>
   sets the attribute before first paint.
   ------------------------------------------------------------ */
:root {
  /* Grayscale ramp */
  --gray-0:  #ffffff;
  --gray-50: #f7f7f8;
  --gray-100:#eeeef0;
  --gray-200:#e2e2e6;
  --gray-300:#c9c9cf;
  --gray-400:#9a9aa3;
  --gray-500:#6f6f79;
  --gray-600:#52525b;
  --gray-700:#3a3a42;
  --gray-800:#26262c;
  --gray-900:#17171b;
  --gray-950:#0d0d10;

  /* Semantic tokens (light theme defaults) */
  --bg:            var(--gray-0);
  --bg-soft:       var(--gray-50);
  --bg-elevated:   var(--gray-0);
  --bg-sunken:     var(--gray-100);
  --text:          var(--gray-800);
  --text-strong:   var(--gray-900);
  --text-muted:    var(--gray-500);
  --border:        var(--gray-200);
  --border-strong: var(--gray-300);

  /* Brand accent: Italian flag green */
  --accent:        #008c45;
  --accent-hover:  #006f38;
  --accent-soft:   #e6f4ea;
  --accent-contrast:#ffffff;

  --danger:  #d32f2f;
  --success: #008c45;
  --warning: #b26a00;

  /* Minesweeper LED counter (classic dark window) */
  --led-bg:    #1a1a1a;
  --led-text:  #ff4436;

  /* Number colors (classic-inspired, tuned for contrast) */
  --n1: #1565c0;
  --n2: #2e7d32;
  --n3: #d32f2f;
  --n4: #4527a0;
  --n5: #8d2f2f;
  --n6: #00838f;
  --n7: #1f1f24;
  --n8: #71717a;

  /* Board sizing (overridden by JS on small screens) */
  --cell-size: 34px;
  --cell-gap: 2px;

  /* Shape & depth */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 14px rgba(0,0,0,.10);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.14);

  /* Typography */
  --font-body: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: Consolas, "Cascadia Mono", Menlo, "Courier New", monospace;

  /* Layout */
  --container: 1080px;
  --header-h: 60px;
}

/* Dark theme overrides */
[data-theme="dark"] {
  --bg:            var(--gray-950);
  --bg-soft:       #15151a;
  --bg-elevated:   #1e1e24;
  --bg-sunken:     #121216;
  --text:          #d7d7dd;
  --text-strong:   #f2f2f5;
  --text-muted:    #9a9aa3;
  --border:        #2c2c34;
  --border-strong: #3d3d47;

  --accent:        #2fb767;
  --accent-hover:  #43c97a;
  --accent-soft:   #11321f;

  --led-bg:    #101013;
  --led-text:  #ff5d4f;

  --n1: #6ea8ff;
  --n2: #7fd68a;
  --n3: #ff7a70;
  --n4: #b39ddb;
  --n5: #f2a56b;
  --n6: #5fd4dc;
  --n7: #e6e6ea;
  --n8: #a0a0aa;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 14px rgba(0,0,0,.5);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.6);
}

/* ------------------------------------------------------------
   2. BASE RESET & TYPOGRAPHY
   ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  transition: background-color .25s ease, color .25s ease;
}

h1, h2, h3, h4 {
  color: var(--text-strong);
  line-height: 1.25;
  margin: 0 0 .6em;
  font-weight: 700;
}
h1 { font-size: clamp(1.7rem, 3.5vw, 2.4rem); letter-spacing: -.02em; }
h2 { font-size: clamp(1.35rem, 2.6vw, 1.7rem); letter-spacing: -.01em; margin-top: 2em; }
h3 { font-size: 1.15rem; margin-top: 1.6em; }

p { margin: 0 0 1em; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; height: auto; }

code {
  font-family: var(--font-mono);
  font-size: .9em;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .1em .4em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: .5em 1em;
  z-index: 100;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ------------------------------------------------------------
   3. LAYOUT CONTAINERS
   ------------------------------------------------------------ */
.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 20px;
}

.page-main { min-height: 60vh; padding: 32px 0 64px; }

/* Narrow reading column for article pages */
.article { max-width: 760px; margin: 0 auto; }

.breadcrumbs {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 1.5em;
}
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs .sep { margin: 0 .45em; opacity: .6; }

/* Hero section (home page) */
.hero {
  text-align: center;
  padding: 1.5em 0 1em;
}
.hero p.lead {
  font-size: 1.1rem;
  color: var(--text-muted);
  max-width: 640px;
  margin: 0 auto 1em;
}

/* ------------------------------------------------------------
   4. HEADER & NAVIGATION
   ------------------------------------------------------------ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--header-h);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text-strong);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.brand .logo { width: 28px; height: 28px; flex: none; }
.brand .brand-domain { color: var(--text-muted); font-weight: 600; font-size: .85em; }

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.main-nav a {
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.main-nav a:hover { background: var(--bg-sunken); color: var(--accent); text-decoration: none; }
.main-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.header-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-sunken); border-color: var(--border-strong); }

/* Hamburger: hidden on desktop */
.nav-toggle { display: none; }

/* Mobile navigation drawer */
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  .main-nav {
    position: absolute;
    top: var(--header-h);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    padding: 8px 16px 16px;
    display: none;
  }
  body.nav-open .main-nav { display: flex; }
  .main-nav a { padding: 12px; font-size: 1rem; }
}

/* ------------------------------------------------------------
   5. FOOTER
   ------------------------------------------------------------ */
.site-footer {
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  margin-top: 48px;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 32px;
  padding: 40px 0 24px;
}
@media (max-width: 860px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .footer-grid { grid-template-columns: 1fr; }
}

.footer-brand p { color: var(--text-muted); font-size: .9rem; margin-top: .8em; max-width: 300px; }
.footer-brand .brand { font-size: 1.05rem; }

.footer-col h4 {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.footer-col ul { list-style: none; margin: 0; padding: 0; }
.footer-col li { margin: 0 0 8px; }
.footer-col a { color: var(--text); font-size: .92rem; }
.footer-col a:hover { color: var(--accent); }

.footer-bottom {
  border-top: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  align-items: center;
  justify-content: space-between;
  font-size: .85rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------
   6. BUTTONS & FORMS
   ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease;
}
.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-contrast); }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent); }

/* CTA row under game */
.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 24px 0;
}

/* Generic form fields (contact page) */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
.field input:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

/* ------------------------------------------------------------
   7. CARDS & GRIDS
   ------------------------------------------------------------ */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, transform .15s ease;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.card h3 a { color: var(--text-strong); }
.card h3 a:hover { color: var(--accent); text-decoration: none; }
.card p { color: var(--text-muted); font-size: .92rem; margin: 0; }
.card .card-icon { font-size: 1.6rem; display: block; margin-bottom: 10px; }

.card .card-meta {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 10px;
}

/* Difficulty cards on home */
.diff-card .badge-grid { font-family: var(--font-mono); font-size: .85rem; color: var(--text-muted); }

/* Info / note boxes */
.note {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 1.2em 0;
  font-size: .95rem;
}
.note-warning {
  background: color-mix(in srgb, var(--warning) 12%, var(--bg));
  border-left-color: var(--warning);
}

/* ------------------------------------------------------------
   8. TABLES
   ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; margin: 1.2em 0; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .93rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
table.data th, table.data td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.data th {
  background: var(--bg-soft);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--bg-soft); }

/* ------------------------------------------------------------
   9. ARTICLE TYPOGRAPHY (guide / blog)
   ------------------------------------------------------------ */
.article h2 { border-bottom: 2px solid var(--border); padding-bottom: .3em; }
.article ul, .article ol { padding-left: 1.4em; margin: 0 0 1em; }
.article li { margin-bottom: .4em; }

.article figure { margin: 1.4em 0; text-align: center; }
.article figcaption {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: .6em;
}

/* Article meta line (blog posts) */
.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  color: var(--text-muted);
  font-size: .88rem;
  margin-bottom: 2em;
}

/* ------------------------------------------------------------
   10. GAME WIDGET & BOARD
   ------------------------------------------------------------ */
.game-widget {
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 18px;
}

/* Top bar: mine counter - reset face - timer */
.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.led {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--led-text);
  background: var(--led-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  min-width: 86px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.reset-btn {
  font-size: 1.8rem;
  line-height: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 6px 14px;
  cursor: pointer;
  transition: transform .1s ease;
}
.reset-btn:hover { background: var(--bg-sunken); }
.reset-btn:active { transform: scale(.94); }

/* Board area: horizontally scrollable on small screens (Expert) */
.board-wrap {
  overflow-x: auto;
  padding: 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.board {
  display: grid;
  gap: var(--cell-gap);
  width: max-content;
  margin: 0 auto;
  touch-action: manipulation;
}

/* Single cell (a <button> element) */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: calc(var(--cell-size) * .52);
  font-weight: 800;
  line-height: 1;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-elevated);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), inset 0 -2px 0 rgba(0,0,0,.08);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
[data-theme="dark"] .cell {
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), inset 0 -2px 0 rgba(0,0,0,.3);
}
.cell:hover:not(.revealed) { background: var(--bg-soft); }
.cell:active:not(.revealed) { box-shadow: none; }

/* Revealed cell: flat / sunken look */
.cell.revealed {
  background: var(--bg-sunken);
  border-color: var(--border);
  box-shadow: none;
  cursor: default;
}

/* Wrong flag marker shown after a loss */
.cell.wrong-flag { color: var(--danger); }

/* Mine that exploded the board: highlighted red */
.cell.boom { background: var(--danger) !important; color: #fff; }

/* Number colors 1-8 */
.cell.n1 { color: var(--n1); }
.cell.n2 { color: var(--n2); }
.cell.n3 { color: var(--n3); }
.cell.n4 { color: var(--n4); }
.cell.n5 { color: var(--n5); }
.cell.n6 { color: var(--n6); }
.cell.n7 { color: var(--n7); }
.cell.n8 { color: var(--n8); }

/* Toolbar under the board */
.game-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.diff-group { display: flex; flex-wrap: wrap; gap: 6px; }

.diff-btn {
  font-family: inherit;
  font-size: .85rem;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.diff-btn:hover { border-color: var(--accent); color: var(--accent); }
.diff-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

/* Flag mode toggle (mainly for touch devices) */
.flag-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.flag-toggle[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Status message under the board */
.game-msg {
  text-align: center;
  font-weight: 600;
  margin: 14px 0 4px;
  min-height: 1.5em;
}
.game-msg.win { color: var(--success); }
.game-msg.lose { color: var(--danger); }

.best-line {
  text-align: center;
  font-size: .88rem;
  color: var(--text-muted);
  margin: 4px 0 0;
}
.best-line a { font-size: .85rem; }

/* Small-screen adjustments */
@media (max-width: 640px) {
  .game-widget { padding: 12px; }
  .led { font-size: 1.2rem; min-width: 70px; padding: 3px 8px; }
  .reset-btn { font-size: 1.5rem; padding: 4px 10px; }
}

/* ------------------------------------------------------------
   11. DEMO BOARDS (static examples inside articles)
   ------------------------------------------------------------ */
.demo-board {
  display: inline-grid;
  gap: 3px;
  padding: 8px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.demo-cell {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.05rem;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
}
.demo-cell.hidden { background: var(--bg-elevated); box-shadow: inset 0 -2px 0 rgba(0,0,0,.08); }
.demo-cell.open   { background: var(--bg-sunken); border-color: var(--border); }
.demo-cell.c1 { color: var(--n1); }
.demo-cell.c2 { color: var(--n2); }
.demo-cell.c3 { color: var(--n3); }
.demo-cell.c4 { color: var(--n4); }
.demo-cell.c5 { color: var(--n5); }
.demo-cell.c6 { color: var(--n6); }
.demo-cell.mine { background: var(--gray-800); border-color: var(--gray-900); }
[data-theme="dark"] .demo-cell.mine { background: var(--gray-600); }
.demo-cell.flag { color: var(--danger); }

/* ------------------------------------------------------------
   12. COOKIE CONSENT BANNER
   ------------------------------------------------------------ */
.cookie-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 18px 20px;
}
.cookie-banner p { font-size: .9rem; margin: 0 0 12px; }
.cookie-banner p a { font-weight: 600; }

.cookie-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cookie-actions .btn { padding: 8px 14px; font-size: .85rem; }

/* Inline preferences panel */
.cookie-prefs {
  display: none;
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 12px;
}
.cookie-prefs.open { display: block; }
.cookie-prefs label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .9rem;
  margin-bottom: 8px;
}
.cookie-prefs input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.cookie-prefs .btn { margin-top: 4px; }

/* ------------------------------------------------------------
   13. TEST BANNER (zh-cn staging pages only)
   ------------------------------------------------------------ */
.test-banner {
  background: #b26a00;
  color: #fff;
  text-align: center;
  font-size: .85rem;
  font-weight: 600;
  padding: 6px 16px;
}

/* ------------------------------------------------------------
   14. UTILITIES & RESPONSIVE
   ------------------------------------------------------------ */
.text-center { text-align: center; }
.muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }

/* Two-column helper for command lists */
.split-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 640px) {
  .split-2 { grid-template-columns: 1fr; }
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* 404 page */
.error-page { text-align: center; padding: 60px 0; }
.error-page .big-emoji { font-size: 4rem; display: block; margin-bottom: .3em; }
