/* ============================================================
   eink.css — design system for E-Ink displays.
   Black on paper-white, no motion, thick strokes, big targets.
   ============================================================ */

:root {
  --ink: #000;
  --paper: #fff;
  --muted: #444;
  --border-thin: 2px solid var(--ink);
  --border-thick: 3px solid var(--ink);
}

* { box-sizing: border-box; transition: none; animation: none; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Georgia, serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

.container {
  max-width: 30rem;
  margin: 0 auto;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

@media (min-width: 48rem) {
  .container { max-width: 38rem; }
}

.app-header h1 {
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  border-bottom: var(--border-thick);
  padding-bottom: 0.5rem;
  margin: 0.5rem 0 1rem;
}

.back-link {
  display: inline-block;
  margin: 0.25rem 0 0.75rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: bold;
  min-height: 44px;
  padding: 0.25rem;
}

.back-link:focus-visible,
.back-link:active { background: var(--ink); color: var(--paper); outline: none; }

/* ---------- Home menu ---------- */

.menu-list { display: flex; flex-direction: column; gap: 0.9rem; }

.menu-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
  min-height: 84px;
  padding: 1rem 1.25rem;
  border: var(--border-thick);
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.menu-item:active,
.menu-item:focus-visible { background: var(--ink); color: var(--paper); outline: none; }

.menu-item-name { font-size: 1.35rem; font-weight: bold; }
.menu-item-sub { font-size: 0.95rem; color: var(--muted); }

.menu-item:focus-visible .menu-item-sub,
.menu-item:active .menu-item-sub { color: var(--paper); }

/* ---------- Buttons ---------- */

button {
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
  border: var(--border-thick);
  min-height: 56px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { opacity: 0.4; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.75rem 0; }

.seg { display: flex; margin: 0.5rem 0; }
.seg button { flex: 1; border-right-width: 0; min-height: 56px; }
.seg button:last-child { border-right-width: 3px; }

button.is-selected,
button:active { background: var(--ink); color: var(--paper); outline: none; }

button:focus-visible { background: var(--paper); color: var(--ink);
  outline: 3px dotted var(--ink); outline-offset: -7px; }

.status { min-height: 1.6em; font-weight: bold; margin: 0.5rem 0; }

.scorebar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border: var(--border-thin);
  padding: 0.5rem 0.9rem;
  margin: 0.75rem 0;
  font-weight: bold;
}

/* ---------- Boards & square cells ---------- */

.board {
  display: grid;
  border: var(--border-thick);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.cell {
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  min-height: 0;
  background: var(--paper);
  border-right: var(--border-thin);
  border-bottom: var(--border-thin);
}

.cell::before { content: ""; display: block; padding-top: 100%; }

.cell-content {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* ---------- XO ---------- */

.xo-grid { grid-template-columns: repeat(3, 1fr); }
.xo-grid .cell:nth-child(3n) { border-right: 0; }
.xo-grid .cell:nth-last-child(-n+3) { border-bottom: 0; }
.xo-grid .cell-content { font-size: 2.6rem; }
.xo-grid .cell.is-win,
.xo-grid .cell.is-win .cell-content { background: var(--ink); color: var(--paper); }

/* ---------- Sudoku ---------- */

.sudoku-grid { grid-template-columns: repeat(9, 1fr); }
.sudoku-grid .cell { border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.sudoku-grid .cell.b-right { border-right: var(--border-thick); }
.sudoku-grid .cell.b-bottom { border-bottom: var(--border-thick); }
.sudoku-grid .cell:nth-child(9n) { border-right: 0; }
.sudoku-grid .cell:nth-last-child(-n+9) { border-bottom: 0; }
.sudoku-grid .cell-content { font-size: 1.05rem; }
.sudoku-grid .cell.is-given .cell-content { font-weight: 900; }
.sudoku-grid .cell.is-selected { background: var(--ink); }
.sudoku-grid .cell.is-selected .cell-content { color: var(--paper); }
.sudoku-grid .cell.is-conflict { background: var(--ink); }
.sudoku-grid .cell.is-conflict .cell-content {
  color: var(--paper);
  text-decoration: underline;
}
.sudoku-grid .cell.is-related .cell-content { text-decoration: underline; }

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  font-size: 0.55em;
  font-weight: normal;
}
.note { display: flex; align-items: center; justify-content: center; }

.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-top: 0.9rem;
}
.keypad .num { font-size: 1.3rem; }

/* ---------- Memory ---------- */

.memory-grid .card-face { font-size: 2rem; }
.memory-grid .cell.is-up,
.memory-grid .cell.is-matched { background: var(--ink); }
.memory-grid .cell.is-up .card-face,
.memory-grid .cell.is-matched .card-face { color: var(--paper); }

/* ---------- 2048 ---------- */

.g2048-grid {
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 6px;
  touch-action: none;
}
.g2048-grid .cell { border: 2px solid var(--muted); border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); }
.g2048-grid .cell-content { font-size: 1.5rem; }

.tile.t2    { background: var(--paper); }
.tile.t4    { background: #ececec; }
.tile.t8    { background: #d6d6d6; }
.tile.t16   { background: #bcbcbc; }
.tile.t32   { background: #a0a0a0; }
.tile.t64   { background: #818181; color: #fff; }
.tile.t128  { background: #666666; color: #fff; }
.tile.t256  { background: #4d4d4d; color: #fff; }
.tile.t512  { background: #383838; color: #fff; }
.tile.t1024 { background: #222222; color: #fff; border-color: var(--ink); }
.tile.t2048 { background: #000000; color: #fff; border-color: var(--ink); }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  justify-content: center;
  margin: 1rem auto 0;
}
.dpad .up    { grid-column: 2; grid-row: 1; }
.dpad .left  { grid-column: 1; grid-row: 2; }
.dpad .down  { grid-column: 2; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }

/* ---------- Panels ---------- */

.panel {
  border: var(--border-thick);
  padding: 1.25rem;
  margin-top: 1rem;
  text-align: center;
}
.panel h2 { margin: 0 0 0.5rem; }

@media (min-width: 48rem) {
  .g2048-grid .cell-content { font-size: 2rem; }
  .memory-grid .card-face { font-size: 2.6rem; }
}
