/* ISP Arcade — shared theme used by the portal and every game.
   Styled after the New York Times Games look: clean white, near-black
   ink, serif display headings, pill buttons, and a games-blue accent. */

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

/* display:flex on overlays would otherwise override the hidden attribute */
[hidden] {
  display: none !important;
}

:root {
  --bg: #f4f4f2;
  --card: #ffffff;
  --ink: #121212;
  --ink-soft: #6e6e6e;
  --accent: #4a63d0;
  --accent-soft: #eaeefb;
  --line: #e2e2e2;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  --serif: "Georgia", "Times New Roman", serif;
  --found-1: #ffd6a5;
  --found-2: #caffbf;
  --found-3: #a0c4ff;
  --found-4: #ffc6ff;
  --found-5: #fdffb6;
  --found-6: #9bf6ff;
  --found-7: #ffadad;
  --found-8: #bdb2ff;
  --radius: 16px;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  /* Sized for an iPad Pro 13" in landscape (1376×1032 points) */
  max-width: 1376px;
  margin: 0 auto;
  padding: 8px 16px 12px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 0 10px;
  flex-shrink: 0;
}

.logo {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.logo span {
  color: var(--accent);
}

a.logo-link {
  text-decoration: none;
  color: inherit;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.3rem;
  font-weight: 700;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px 14px;
  min-width: 84px;
  text-align: center;
}

.topbar-buttons {
  margin-left: auto;
  display: flex;
  gap: 10px;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid #bdbdbd;
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease;
  touch-action: manipulation;
  text-decoration: none;
  display: inline-block;
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.btn-pause {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
}

.btn-big {
  font-size: 1.15rem;
  padding: 14px 28px;
}

.back-btn {
  padding: 10px 14px;
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px 10px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  font: inherit;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 9px;
  padding: 7px 13px;
  cursor: pointer;
  touch-action: manipulation;
}

.seg-btn.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.select {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 130px;
}

/* ---------- Pause overlay ---------- */
.blurred {
  filter: blur(14px) !important;
  pointer-events: none;
}

.pause-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.pause-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  padding: 28px 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.pause-icon {
  font-size: 2rem;
}

.pause-card p {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink-soft);
}

/* ---------- Toast (shared by every game) ---------- */
.toast {
  position: fixed;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  border-radius: 12px;
  padding: 12px 22px;
  z-index: 40;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(45, 42, 38, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  background: var(--card);
  border-radius: 24px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-emoji {
  font-size: 3rem;
  margin-bottom: 8px;
}

.modal h2 {
  font-family: var(--serif);
  margin-bottom: 10px;
}

.win-time {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.win-note {
  color: var(--ink-soft);
  font-weight: 600;
  margin-top: 6px;
  min-height: 1.4em;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}

.scores-body {
  text-align: left;
  margin-top: 8px;
  max-height: 50vh;
  overflow-y: auto;
}

.scores-body h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin: 14px 0 6px;
}

.scores-body table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.scores-body td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}

.scores-body td:last-child {
  text-align: right;
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.88rem;
}

.scores-body .best-time {
  color: var(--accent);
}

.scores-empty {
  color: var(--ink-soft);
  font-weight: 600;
  padding: 16px 0;
  text-align: center;
}

/* ---------- Large screens (iPad Pro 13" landscape and up) ---------- */
@media (min-width: 1280px) and (min-height: 900px) {
  html {
    font-size: 19px;
  }

  html:has(.app.portal) {
    font-size: 16px;
  }

  .app {
    padding: 14px 24px 18px;
  }

  .topbar {
    gap: 16px;
    padding: 6px 0 14px;
  }
}

/* ---------- Narrow screens ---------- */
@media (max-width: 760px) {
  .app {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .controls .btn-ghost {
    margin-left: 0;
  }
}

/* Portals on smaller screens scroll with flexible columns */
@media (max-width: 1180px), (max-height: 900px) {
  .app.portal {
    overflow-y: auto;
  }

  .game-cards {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

/* Soft elevation for card surfaces across every game */
.game-card,
.controls,
.setup-card,
.puzzle-card,
.word-panel,
.hunt-panel,
.emoji-panel,
.turn-card,
.timer,
.board {
  box-shadow: var(--shadow);
}

/* ---------- Portal ---------- */
.app.portal {
  /* Compact enough to fit an iPad landscape viewport (including Safari's
     toolbar) without scrolling; if a screen is smaller than that, scroll
     gracefully — cards must never compress into each other. */
  overflow-y: auto;
}

.app.portal .game-icon {
  height: clamp(56px, 8vh, 84px);
}

.portal-hero {
  text-align: center;
  padding: 10px 0 4px;
  flex-shrink: 0;
}

.portal-hero h1 {
  /* Modern, not fancy: bold tight-tracked sans for the masthead */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -1px;
}

.portal-hero h1 span {
  color: var(--accent);
}

.portal-hero p {
  color: var(--ink-soft);
  font-weight: 700;
  margin-top: 2px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.portal-date {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  margin-top: 2px;
  font-size: 0.85rem;
}

.masthead-rule {
  max-width: 1050px;
  margin: 8px auto 0;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  height: 4px;
}

.section-title {
  text-align: center;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-top: 8px;
  flex-shrink: 0;
}

.section-title.mp-title {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #d5d5d3;
}

.game-card.mp-card {
  border-color: var(--accent);
  border-width: 2px;
}

.game-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  justify-content: center;
  gap: 12px;
  padding: 8px 0 2px;
  max-width: 1240px;
  margin: 0 auto;
  width: 100%;
  flex-shrink: 0;
}

.game-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 8px 12px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.game-card:active,
.game-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.game-card .game-icon {
  font-size: 2.3rem;
  border-radius: 10px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -8px -8px 2px;
}

/* NYT Games-app style brand colors, one per game */
.tile-search { background: #a7d8c6; }
.tile-groups { background: #b4a8ff; }
.tile-sudoku { background: #fb9b00; }
.tile-cross { background: #7aa2ee; }
.tile-race { background: #f28585; }
.tile-emoji { background: #f6b8d0; }
.tile-hunt { background: #90cdea; }
.tile-wordle { background: #6aaa64; }
.tile-bee { background: #f7da21; }

.wordle-glyph {
  color: #fff;
  font-weight: 800;
  font-size: 0.9em;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.game-card h2 {
  font-family: var(--serif);
  font-size: 1.08rem;
  padding: 0 5px;
}

.game-card p {
  padding: 0 5px;
  font-size: 0.8rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.game-card .game-best {
  padding: 0 5px;
  font-size: 0.75rem;
  min-height: 1em;
}

.game-card .play-chip {
  margin: 2px 5px 0;
  padding: 6px 16px;
  font-size: 0.85rem;
}

.game-card p {
  color: var(--ink-soft);
  font-weight: 500;
  line-height: 1.45;
  flex: 1;
}

.game-card .game-best {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.game-card .play-chip {
  align-self: flex-start;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  border-radius: 999px;
  padding: 9px 22px;
}
