*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:            #f5f5f3;
  --color-surface:       #ffffff;
  --color-border:        rgba(0,0,0,0.13);
  --color-border-strong: rgba(0,0,0,0.28);
  --color-text-primary:  #1a1a1a;
  --color-text-secondary:#666;

  /* Cell colors are intentionally FIXED (not theme-swapped):
     unflipped = white, flipped = black, in both light and dark mode. */
  --color-cell-white:    #ffffff;
  --color-cell-black:    #111111;
  --color-cell-white-hover: #e9e9e6;
  --color-cell-black-hover: #2b2b2b;

  --color-btn-bg:        #ffffff;
  --color-btn-border:    rgba(0,0,0,0.2);
  --color-btn-hover:     #efefed;
  --color-win-bg:        #eaf3de;
  --color-win-text:      #3b6d11;
  --color-win-border:    #97c459;

  /* difficulty badge colors (8 levels) */
  --d1-bg:#e1f5ee; --d1-text:#0f6e56; --d1-border:#5dcaa5;
  --d2-bg:#e3f3e1; --d2-text:#256b1a; --d2-border:#7fc46c;
  --d3-bg:#eef3df; --d3-text:#5a6e1a; --d3-border:#b6cc6e;
  --d4-bg:#fbf3da; --d4-text:#8a6a10; --d4-border:#e3bf5e;
  --d5-bg:#fbe9da; --d5-text:#9a5414; --d5-border:#eda06a;
  --d6-bg:#fbe2dc; --d6-text:#a13c22; --d6-border:#ef8a6c;
  --d7-bg:#fadce4; --d7-text:#a3204f; --d7-border:#ee7fa3;
  --d8-bg:#f1ddf7; --d8-text:#6c1d96; --d8-border:#cc89e8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:            #161616;
    --color-surface:       #242424;
    --color-border:        rgba(255,255,255,0.11);
    --color-border-strong: rgba(255,255,255,0.24);
    --color-text-primary:  #f0f0ee;
    --color-text-secondary:#999;

    /* Cell colors stay fixed white/black regardless of theme. */
    --color-cell-white:       #ffffff;
    --color-cell-black:       #111111;
    --color-cell-white-hover: #d8d8d4;
    --color-cell-black-hover: #2b2b2b;

    --color-btn-bg:        #242424;
    --color-btn-border:    rgba(255,255,255,0.17);
    --color-btn-hover:     #2e2e2e;
    --color-win-bg:        #173404;
    --color-win-text:      #c0dd97;
    --color-win-border:    #3b6d11;

    --d1-bg:#04342c; --d1-text:#5dcaa5; --d1-border:#0f6e56;
    --d2-bg:#143008; --d2-text:#7fc46c; --d2-border:#256b1a;
    --d3-bg:#2c3308; --d3-text:#b6cc6e; --d3-border:#5a6e1a;
    --d4-bg:#3a2c05; --d4-text:#e3bf5e; --d4-border:#8a6a10;
    --d5-bg:#40220a; --d5-text:#eda06a; --d5-border:#9a5414;
    --d6-bg:#3f1a0e; --d6-text:#ef8a6c; --d6-border:#a13c22;
    --d7-bg:#3d0f23; --d7-text:#ee7fa3; --d7-border:#a3204f;
    --d8-bg:#2b0e3c; --d8-text:#cc89e8; --d8-border:#6c1d96;
  }
}

/* ── Layout ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
  max-width: 760px;
}

.hidden { display: none !important; }

/* ── Select screen ── */
.app-title {
  font-size: clamp(26px, 5.5vw, 40px);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: center;
}

.app-sub {
  font-size: 15px;
  color: var(--color-text-secondary);
  text-align: center;
  line-height: 1.6;
}

.diff-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  width: 100%;
}

.diff-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 1.1rem 0.9rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s, background 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.diff-card:hover {
  border-color: var(--color-border-strong);
  background: var(--color-btn-hover);
}

.diff-card:active { transform: scale(0.97); }

.diff-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid;
  white-space: nowrap;
}

.diff-grid-label {
  font-size: 24px;
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: 0.03em;
}

.diff-desc {
  font-size: 11px;
  color: var(--color-text-secondary);
}

/* Mini preview grid */
.diff-preview {
  display: grid;
  gap: 2px;
  margin-top: 2px;
}

.diff-preview .pc {
  background: var(--color-cell-white);
  border: 1px solid var(--color-border);
  border-radius: 2px;
}

/* ── Game screen ── */
.game-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.game-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-icon {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text-secondary);
  font-size: 18px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { background: var(--color-btn-hover); color: var(--color-text-primary); }

.title {
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 600;
  letter-spacing: 0.05em;
}

.diff-pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid;
  white-space: nowrap;
}

/* Stats */
.stats { display: flex; gap: 28px; }

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-val {
  font-size: 26px;
  font-weight: 500;
  line-height: 1;
}

.stat-lbl {
  font-size: 10px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── Grid ── */
.grid {
  display: grid;
  gap: var(--gap, 6px);
  touch-action: manipulation;
}

.cell {
  background: var(--color-cell-white);
  border: 1px solid var(--color-border);
  border-radius: var(--cell-radius, 8px);
  cursor: pointer;
  transition: background 0.11s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.cell:hover  { background: var(--color-cell-white-hover); border-color: var(--color-border-strong); }
.cell:active { transform: scale(0.91); }
.cell.black  { background: var(--color-cell-black); border-color: var(--color-cell-black); }
.cell.black:hover { background: var(--color-cell-black-hover); }

/* Win */
.win-msg {
  font-size: 16px;
  font-weight: 500;
  padding: 10px 20px;
  background: var(--color-win-bg);
  color: var(--color-win-text);
  border: 1px solid var(--color-win-border);
  border-radius: 10px;
  display: none;
  text-align: center;
}
.win-msg.show { display: block; }

/* Buttons */
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.btn {
  font-size: 14px;
  font-weight: 500;
  padding: 10px 26px;
  background: var(--color-btn-bg);
  color: var(--color-text-primary);
  border: 1px solid var(--color-btn-border);
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.1s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover  { background: var(--color-btn-hover); }
.btn:active { transform: scale(0.97); }

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

/* ── Responsive ── */
@media (max-width: 480px) {
  .diff-cards { grid-template-columns: repeat(2, 1fr); }
  .diff-card  { padding: 0.9rem 0.7rem; }
  .diff-grid-label { font-size: 20px; }
  .stats { gap: 18px; }
  .stat-val { font-size: 22px; }
}

@media (max-width: 340px) {
  .diff-cards { grid-template-columns: 1fr 1fr; gap: 8px; }
}

/* ── About overlay ── */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.55);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.overlay.hidden { display: none !important; }

.about-card {
  position: relative;
  width: 100%; max-width: 360px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 30px 24px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.3);
}
.about-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none;
  font-size: 24px; line-height: 1;
  color: var(--color-text-secondary); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.about-close:hover { color: var(--color-text-primary); }

.about-title {
  font-size: 26px; font-weight: 600; letter-spacing: 0.03em; margin-bottom: 10px;
}
.about-lead {
  font-size: 14px; line-height: 1.6; color: var(--color-text-secondary);
}
.about-divider { height: 1px; background: var(--color-border); margin: 18px 0; }
.about-credit { font-size: 13.5px; color: var(--color-text-primary); margin-bottom: 3px; }
.about-credit strong { color: var(--d1-text); }
.about-studio { font-size: 16px; font-weight: 600; letter-spacing: 0.02em; margin-bottom: 10px; }
.about-meta {
  font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--color-text-secondary); margin-bottom: 5px;
}
.about-copy { font-size: 11px; color: var(--color-text-secondary); margin-bottom: 20px; }
.about-done { width: 100%; }

/* About link on the select screen */
.select-footer { display: flex; justify-content: center; }
.about-link {
  background: none; border: none;
  font-size: 13px; color: var(--color-text-secondary);
  cursor: pointer; padding: 6px 10px; letter-spacing: 0.04em;
  text-decoration: underline; text-underline-offset: 3px;
  -webkit-tap-highlight-color: transparent;
}
.about-link:hover { color: var(--color-text-primary); }
