/* FreeHarbor — Material Design 3 (Harbor Family Palette) + Dustland Minimalism */
:root {
  --navy: #1E3568;
  --navy-dark: #132245;
  --navy-container: #D8E2FF;
  --on-navy-container: #0A1C43;
  --teal: #16BFA9;
  --teal-dark: #006B5E;
  --teal-container: #BFF4EA;
  --on-teal-container: #00201B;

  --surface: #EDF1F8;
  --surface-lowest: #FFFFFF;
  --surface-low: #E3E9F4;
  --surface-mid: #DCE3F0;
  --surface-high: #D4DCEC;
  --text: #181C24;
  --muted: #424959;
  --outline: #BAC3D6;
  --grid-line: #8C98B0;
  --grid-bold: #1E3568;
  --danger: #BA1A1A;
  --danger-bg: #FFDAD6;
  --on-danger-bg: #410002;
  --conflict-bg: rgba(186, 26, 26, 0.16);
  --conflict-ring: #C62828;

  /* Muted Colorblind-Friendly Region Palette (Light) */
  --reg-0: #DCE8FA;
  --reg-1: #FBE4D8;
  --reg-2: #D8F0E5;
  --reg-3: #EFE1FA;
  --reg-4: #FAF0CA;
  --reg-5: #FADCE6;
  --reg-6: #D7EEF2;
  --reg-7: #E8EAD6;
  --reg-8: #E6E0D8;
  --reg-9: #D9E2EC;

  --topbar-bg: rgba(237, 241, 248, 0.92);
  --nav-bg: rgba(255, 255, 255, 0.94);
  --radius-card: 20px;
  --radius-btn: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy-container: #1E3568;
    --on-navy-container: #D8E2FF;
    --teal-container: #005046;
    --on-teal-container: #9DF2E3;

    --surface: #0C1018;
    --surface-lowest: #232B3D;
    --surface-low: #151A25;
    --surface-mid: #1B2130;
    --surface-high: #242B3D;
    --text: #E4E8F2;
    --muted: #B0B7C8;
    --outline: #3C465E;
    --grid-line: #4C5874;
    --grid-bold: #A8BEE8;
    --danger: #FFB4AB;
    --danger-bg: #93000A;
    --on-danger-bg: #FFDAD6;
    --conflict-bg: rgba(255, 107, 107, 0.24);
    --conflict-ring: #FF7B7B;

    /* Muted Colorblind-Friendly Region Palette (Dark) */
    --reg-0: #24354F;
    --reg-1: #4A332A;
    --reg-2: #203F35;
    --reg-3: #3A2C4D;
    --reg-4: #463E22;
    --reg-5: #4A2B38;
    --reg-6: #1F3C45;
    --reg-7: #353B27;
    --reg-8: #3D352E;
    --reg-9: #2A3442;

    --topbar-bg: rgba(12, 16, 24, 0.92);
    --nav-bg: rgba(21, 26, 37, 0.95);
  }
}

:root[data-theme="dark"] {
  --navy-container: #1E3568;
  --on-navy-container: #D8E2FF;
  --teal-container: #005046;
  --on-teal-container: #9DF2E3;

  --surface: #0C1018;
  --surface-lowest: #232B3D;
  --surface-low: #151A25;
  --surface-mid: #1B2130;
  --surface-high: #242B3D;
  --text: #E4E8F2;
  --muted: #B0B7C8;
  --outline: #3C465E;
  --grid-line: #4C5874;
  --grid-bold: #A8BEE8;
  --danger: #FFB4AB;
  --danger-bg: #93000A;
  --on-danger-bg: #FFDAD6;
  --conflict-bg: rgba(255, 107, 107, 0.24);
  --conflict-ring: #FF7B7B;

  --reg-0: #24354F;
  --reg-1: #4A332A;
  --reg-2: #203F35;
  --reg-3: #3A2C4D;
  --reg-4: #463E22;
  --reg-5: #4A2B38;
  --reg-6: #1F3C45;
  --reg-7: #353B27;
  --reg-8: #3D352E;
  --reg-9: #2A3442;

  --topbar-bg: rgba(12, 16, 24, 0.92);
  --nav-bg: rgba(21, 26, 37, 0.95);
}

:root[data-theme="amoled"] {
  --navy-container: #182B54;
  --on-navy-container: #D8E2FF;
  --teal-container: #00463D;
  --on-teal-container: #9DF2E3;

  --surface: #000000;
  --surface-lowest: #12161F;
  --surface-low: #0A0D13;
  --surface-mid: #10141D;
  --surface-high: #191F2C;
  --text: #EEF2FA;
  --muted: #A4ACBE;
  --outline: #2C3448;
  --grid-line: #3C465E;
  --grid-bold: #A8BEE8;
  --danger: #FFB4AB;
  --danger-bg: #7A0008;
  --on-danger-bg: #FFDAD6;
  --conflict-bg: rgba(255, 107, 107, 0.28);
  --conflict-ring: #FF7B7B;

  --reg-0: #1B2A40;
  --reg-1: #3A261E;
  --reg-2: #173028;
  --reg-3: #2E223E;
  --reg-4: #383119;
  --reg-5: #3B202B;
  --reg-6: #162E36;
  --reg-7: #2A2F1E;
  --reg-8: #302923;
  --reg-9: #212A36;

  --topbar-bg: rgba(0, 0, 0, 0.94);
  --nav-bg: rgba(10, 13, 19, 0.96);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100dvh;
  overflow-x: clip;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  font-family: "Google Sans", "Product Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea {
  user-select: text;
  -webkit-user-select: text;
}

.hidden { display: none !important; }

.app-shell {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

/* Top App Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid transparent;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(19, 34, 69, 0.16);
}
.brand-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }

.topbar-center { text-align: center; min-width: 0; }
.brand-title { font-size: 19px; font-weight: 700; letter-spacing: -0.3px; line-height: 1.15; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.circle-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.circle-icon-btn:active { background: var(--surface-mid); }

/* Content & Cards */
.content {
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--surface-lowest);
  border: 1px solid var(--outline);
  border-radius: var(--radius-card);
  padding: 16px;
}

.card-navy {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
  color: #F4F7FF;
  border-radius: var(--radius-card);
  padding: 18px;
}
.card-navy .muted, .navy-copy { color: rgba(235, 242, 255, 0.86); font-size: 14px; margin: 0; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.section-title { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -0.2px; }
.muted { color: var(--muted); font-size: 13px; }
.body-copy { font-size: 14px; line-height: 1.5; }

.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--navy-container);
  color: var(--on-navy-container);
}
.pill-teal {
  background: var(--teal-container);
  color: var(--on-teal-container);
}
.pill-done {
  background: var(--teal);
  color: #00231E;
}

/* Dashboard Game Grid */
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 370px) {
  .game-grid { grid-template-columns: 1fr; }
}

.game-card {
  background: var(--surface-lowest);
  border: 1px solid var(--outline);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  text-align: left;
  color: inherit;
  font-family: inherit;
}
.game-card:active { transform: scale(0.98); }
.game-card.daily-done { border-color: var(--teal); }

.game-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.game-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--surface-low);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.game-name { font-size: 16px; font-weight: 700; margin: 0; }
.game-desc { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.3; }
.game-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--surface-mid);
  padding-top: 8px;
  margin-top: auto;
}
.game-meta strong { color: var(--text); font-weight: 600; }

/* Buttons & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-btn);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.12s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #FFFFFF; }
.btn-teal { background: var(--teal); color: #00231E; }
.btn-tonal { background: var(--navy-container); color: var(--on-navy-container); }
.btn-outline { background: transparent; color: var(--text); border: 1.5px solid var(--outline); }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.segmented-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  background: var(--surface-low);
  padding: 4px;
  border-radius: 14px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 8px 6px;
  border-radius: 10px;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--surface-lowest);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* Inputs */
input[type="text"], textarea, select {
  width: 100%;
  border: 1.5px solid var(--outline);
  background: var(--surface-low);
  color: var(--text);
  border-radius: 14px;
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
input[type="text"]:focus, textarea:focus { border-color: var(--teal); }

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  z-index: 30;
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--outline);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
}
.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  font-family: inherit;
}
.nav-pill {
  padding: 4px 18px;
  border-radius: 999px;
  font-size: 18px;
  transition: background 0.15s ease;
}
.nav-btn.active .nav-pill { background: var(--teal-container); color: var(--on-teal-container); }
.nav-btn.active { color: var(--text); font-weight: 700; }
.nav-label { font-size: 12px; }

/* Game Play View */
.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.timer-pill {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
  background: var(--surface-low);
  border: 1px solid var(--outline);
  padding: 6px 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.game-controls-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.ctrl-btn {
  border: 1px solid var(--outline);
  background: var(--surface-lowest);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 6px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.ctrl-btn:active { background: var(--surface-mid); }
.ctrl-btn.active { border-color: var(--teal); background: var(--teal-container); color: var(--on-teal-container); }

/* Shared Logic Grid Engine */
.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 0;
  touch-action: none;
}

.puzzle-grid {
  display: grid;
  width: min(100%, 420px);
  aspect-ratio: 1 / 1;
  background: var(--surface-lowest);
  border: 2.5px solid var(--grid-bold);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.grid-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.1s ease;
  user-select: none;
}
.grid-cell.conflict {
  background-color: var(--conflict-bg) !important;
  box-shadow: inset 0 0 0 2px var(--conflict-ring);
}
.grid-cell.selected {
  box-shadow: inset 0 0 0 2.5px var(--teal);
}
.grid-cell.highlight-same {
  background-color: var(--teal-container) !important;
}
.grid-cell.given {
  color: var(--text);
}
.grid-cell.user-val {
  color: var(--navy);
}
:root[data-theme="dark"] .grid-cell.user-val,
:root[data-theme="amoled"] .grid-cell.user-val {
  color: var(--teal);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .grid-cell.user-val { color: var(--teal); }
}

/* Parity clue badges between cells */
.clue-badge {
  position: absolute;
  z-index: 5;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-lowest);
  border: 1.5px solid var(--grid-bold);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.clue-right { right: -10px; top: 50%; transform: translateY(-50%); }
.clue-bottom { bottom: -10px; left: 50%; transform: translateX(-50%); }

/* Sixes (6x6 Sudoku) */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  place-items: center;
}
.numpad {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}
.num-btn {
  border: 1.5px solid var(--outline);
  background: var(--surface-lowest);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 0;
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.num-btn:active { background: var(--teal-container); }

/* Thread (Hamiltonian Path) SVG overlay */
.thread-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}
.waypoint-dot {
  width: 62%;
  height: 62%;
  border-radius: 50%;
  background: var(--navy);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  z-index: 6;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Word Games: Link, Rung, Weave */
.clue-list { display: flex; flex-direction: column; gap: 8px; }
.clue-card {
  background: var(--surface-low);
  border: 1px solid var(--outline);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.clue-card.locked { opacity: 0.45; font-style: italic; font-weight: 500; }

.rung-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 8px;
  background: var(--surface-low);
  border: 1.5px solid var(--outline);
  border-radius: 14px;
  padding: 10px 12px;
}
.rung-row.cap-row { border-color: var(--teal); background: var(--teal-container); color: var(--on-teal-container); }
.rung-row.solved { border-color: var(--teal); }
.rung-input {
  text-transform: uppercase;
  letter-spacing: 3px;
  font-weight: 800;
  font-size: 16px;
  padding: 8px 10px !important;
  max-width: 140px;
}
.rung-move-btns { display: flex; flex-direction: column; gap: 2px; }
.rung-move-btn {
  border: 1px solid var(--outline);
  background: var(--surface-lowest);
  color: var(--text);
  border-radius: 6px;
  width: 28px;
  height: 24px;
  font-size: 12px;
  cursor: pointer;
}

.weave-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.weave-word-pill {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--surface-low);
  border: 1px solid var(--outline);
  color: var(--text);
}
.weave-word-pill.found {
  background: var(--teal);
  border-color: var(--teal);
  color: #00231E;
  text-decoration: line-through;
}

/* Stats & Charts */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.kpi-card {
  background: var(--surface-low);
  border-radius: 16px;
  padding: 14px;
}
.kpi-val { font-size: 24px; font-weight: 800; color: var(--text); line-height: 1.1; }
.kpi-lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
}
.heatmap-col { display: grid; grid-template-rows: repeat(7, 1fr); gap: 4px; }
.hm-cell {
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  background: var(--surface-mid);
}
.hm-1 { background: rgba(22, 191, 169, 0.35); }
.hm-2 { background: rgba(22, 191, 169, 0.65); }
.hm-3 { background: var(--teal); }

.chart-box {
  width: 100%;
  height: 140px;
  background: var(--surface-low);
  border-radius: 14px;
  padding: 10px;
}

/* Bottom Sheets & Dialogs */
.sheet-backdrop, .dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 12, 20, 0.56);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.dialog-backdrop { align-items: center; padding: 16px; }

.bottom-sheet {
  width: 100%;
  max-width: 600px;
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface-lowest);
  border-radius: 24px 24px 0 0;
  padding: 12px 18px calc(22px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--outline);
  margin: 0 auto 6px;
}
.sheet-tile {
  width: 100%;
  border: 1px solid var(--outline);
  background: var(--surface-low);
  color: var(--text);
  border-radius: 16px;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-decoration: none;
  text-align: left;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}

.dialog-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface-lowest);
  border: 1px solid var(--outline);
  border-radius: 22px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--navy);
  color: #FFFFFF;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Family PIN Lock Screen */
.pin-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pin-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface-lowest);
  border: 1px solid var(--outline);
  border-radius: 24px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(19, 34, 69, 0.14);
}
.pin-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  overflow: hidden;
  margin: 0 auto 12px;
  background: var(--navy);
}
.pin-logo img { width: 100%; height: 100%; object-fit: cover; }
.pin-title { margin: 0; font-size: 22px; font-weight: 700; }
.pin-sub { margin: 6px 0 18px; font-size: 14px; color: var(--muted); }
.pin-input {
  text-align: center;
  font-size: 24px !important;
  letter-spacing: 10px;
  font-weight: 700;
  padding: 12px 14px !important;
}
.pin-error {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
}

