:root {
  --bg: #0f1218;
  --bg-2: #141922;
  --panel: #1b2029;
  --panel-2: #232a36;
  --line: #2a3140;
  --line-2: #39424f;
  --ink: #e8ecf3;
  --dim: #97a1b0;
  --accent: #63b3ff;
  --accent-2: #3d8fe0;
  --good: #5ddb8b;
  --bad: #ff6b6b;
  --warn: #ffd166;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1100px 520px at 50% -12%, #1b2331 0%, transparent 70%),
    var(--bg) fixed;
}

/* ---------- chrome ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 18, 24, 0.82);
  backdrop-filter: blur(8px);
}
header h1 { font-size: 1.05rem; margin: 0; letter-spacing: 0.01em; }
header .spacer { flex: 1 1 auto; }
header a { color: var(--accent); text-decoration: none; font-size: 0.95rem; }
header a:hover { text-decoration: underline; }

main { padding: 1.5rem; max-width: 960px; margin: 0 auto; }
main.wide { max-width: 1120px; }

.controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0 0 0.5rem;
}

.hint { color: var(--dim); margin: 0.25rem 0 1rem; font-size: 0.92rem; }
.readout { font-variant-numeric: tabular-nums; color: var(--ink); }
.state-win { color: var(--good); font-weight: 600; }
.state-lose { color: var(--bad); font-weight: 600; }

button, select {
  font: inherit;
  color: var(--ink);
  background: linear-gradient(var(--panel-2), var(--panel));
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 0.38rem 0.8rem;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.06s ease;
}
button:hover, select:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- hub ---------- */
ul.hub {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}
ul.hub li { margin: 0; }
ul.hub a {
  display: block;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
ul.hub a:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
ul.hub .title { display: block; font-size: 1.05rem; font-weight: 600; color: var(--accent); }
ul.hub .desc { display: block; margin-top: 0.3rem; color: var(--dim); font-size: 0.92rem; }

/* ---------- minesweeper ---------- */
#board {
  display: grid;
  gap: 2px;
  background: #0b0e13;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  width: max-content;
  touch-action: manipulation;
}
#board .cell {
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #2b3341, #232a36);
  border: 0;
  border-radius: 3px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--ink);
}
#board .cell:hover { background: linear-gradient(180deg, #333d4d, #28303d); }
#board .cell.revealed { background: #171c25; cursor: default; color: var(--dim); }
#board .cell.flagged { color: var(--warn); }
#board .cell.mine { background: #5a2323; color: #ffd9d9; }
#board .cell[data-n="1"] { color: #6ea8fe; }
#board .cell[data-n="2"] { color: #5ddb8b; }
#board .cell[data-n="3"] { color: #ff8f8f; }
#board .cell[data-n="4"] { color: #c79bff; }
#board .cell[data-n="5"] { color: #ffb86b; }
#board .cell[data-n="6"] { color: #63d6d6; }
#board .cell[data-n="7"] { color: #e6e6e6; }
#board .cell[data-n="8"] { color: #9aa4b2; }

/* ---------- canvas games ---------- */
.cv {
  display: block;
  background: #0b0e13;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-width: 100%;
  height: auto;
  touch-action: manipulation;
}

/* ---------- solitaire ---------- */
.piles {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 74px;
}
.pile.spacer { width: 1.2rem; min-height: 0; }

.card {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 74px;
  border-radius: 7px;
  background: #f7f9fc;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  color: #14181f;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.card.red { color: #c62828; }
.card:not(.empty):hover { transform: translateY(-2px); }

.card .corner {
  position: absolute;
  top: 3px;
  left: 4px;
  line-height: 1;
  font-size: 0.78rem;
  text-align: center;
}
.card .corner i { display: block; font-style: normal; font-size: 0.7rem; }
.card .pip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  opacity: 0.92;
}

.card.down {
  background:
    repeating-linear-gradient(45deg, #2d3a55 0 5px, #36476a 5px 10px);
  border-color: #22304a;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.06);
}
.card.down::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.pile .card + .card.down { margin-top: -62px; }
.pile .card + .card.up { margin-top: -46px; }

.card.empty {
  background: transparent;
  border: 1px dashed var(--line-2);
  box-shadow: none;
  cursor: default;
}
.card.empty:hover { transform: none; }

.card.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: 0 0 0 4px rgba(99, 179, 255, 0.25);
  transform: translateY(-3px);
}
.pile.drop-ok { box-shadow: inset 0 -2px 0 var(--good); }
.pile.drop-ok .card { outline-color: var(--good); }

@keyframes card-illegal {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.card.illegal { animation: card-illegal 0.16s ease-in-out 2; outline: 2px solid var(--bad); }

.banner {
  margin: 0 0 1rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--ink);
  display: none;
}
.banner.show { display: block; }
.banner.win { border-color: var(--good); color: var(--good); }
