/* Tide Sudoku — BambooTide calm puzzle UI */

:root {
  --tide-50: #f0faf8;
  --tide-100: #d5f0ea;
  --tide-200: #a8e0d4;
  --tide-500: #2a9d8f;
  --tide-600: #1f7a6f;
  --tide-700: #1a6158;
  --tide-800: #164e47;
  --tide-900: #0f332f;
  --tide-950: #0a2220;
  --sand-50: #faf8f5;
  --sand-100: #f3efe8;
  --sand-200: #e8e0d4;
  --ink: #0f332f;
  --muted: rgba(15, 51, 47, 0.55);
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --border: #e8e0d4;
  --cell-hover: rgba(42, 157, 143, 0.08);
  --cell-selected: rgba(42, 157, 143, 0.16);
  --cell-related: rgba(42, 157, 143, 0.07);
  --cell-same: rgba(42, 157, 143, 0.12);
  --given: #0f332f;
  --entry: #1f7a6f;
  --conflict: #b4534a;
  --note: rgba(15, 51, 47, 0.42);
  --shadow: 0 18px 50px -28px rgba(15, 51, 47, 0.35);
  --grid-line: #d5ebe4;
  --grid-box: #1a6158;
  --radius: 1.25rem;
  --font: Inter, system-ui, -apple-system, sans-serif;
  --display: "Cormorant Garamond", Georgia, serif;
}

html.night-tide {
  --ink: #e8f5f2;
  --muted: rgba(232, 245, 242, 0.55);
  --surface: #0f332f;
  --surface-2: #0a2220;
  --border: rgba(168, 224, 212, 0.18);
  --cell-hover: rgba(168, 224, 212, 0.08);
  --cell-selected: rgba(168, 224, 212, 0.16);
  --cell-related: rgba(168, 224, 212, 0.07);
  --cell-same: rgba(42, 157, 143, 0.22);
  --given: #f0faf8;
  --entry: #a8e0d4;
  --conflict: #f0a8a0;
  --note: rgba(232, 245, 242, 0.4);
  --shadow: 0 18px 50px -24px rgba(0, 0, 0, 0.55);
  --grid-line: rgba(168, 224, 212, 0.22);
  --grid-box: #a8e0d4;
  --sand-50: #0a2220;
  --sand-100: #0f332f;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--sand-50);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

body.high-contrast {
  --entry: var(--ink);
  --note: var(--ink);
  --muted: color-mix(in srgb, var(--ink) 72%, transparent);
}

/* Soft horizon wash */
.tide-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, rgba(42, 157, 143, 0.14), transparent 55%),
    radial-gradient(ellipse 70% 40% at 80% 100%, rgba(168, 224, 212, 0.18), transparent 50%),
    linear-gradient(180deg, var(--sand-50) 0%, var(--sand-100) 100%);
  overflow: hidden;
}

html.night-tide .tide-bg {
  background:
    radial-gradient(ellipse 80% 50% at 50% -5%, rgba(42, 157, 143, 0.2), transparent 55%),
    radial-gradient(ellipse 60% 35% at 20% 100%, rgba(26, 97, 88, 0.45), transparent 50%),
    linear-gradient(180deg, #071816 0%, #0a2220 55%, #0f332f 100%);
}

.tide-bg::after {
  content: "";
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: -8%;
  height: 38%;
  background: linear-gradient(
    180deg,
    transparent,
    rgba(42, 157, 143, 0.06) 40%,
    rgba(26, 97, 88, 0.08)
  );
  border-radius: 50% 50% 0 0;
  animation: tide-swell 14s ease-in-out infinite alternate;
  opacity: 0.85;
}

@keyframes tide-swell {
  from {
    transform: translateY(6%) scaleX(1.02);
  }
  to {
    transform: translateY(0) scaleX(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tide-bg::after {
    animation: none;
  }
  .cell.flash,
  .complete-ripple,
  .board.solved {
    animation: none !important;
  }
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand img {
  height: 1.85rem;
  width: auto;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-text strong {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.1;
}

.brand-text span {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Left Comfort · center board · right modes */
.main {
  flex: 1;
  width: 100%;
  max-width: 88rem;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
  display: grid;
  gap: 1.25rem;
}

.side-left { order: 1; }
.play-panel { order: 2; }
.side-right { order: 3; }

@media (min-width: 1100px) {
  .main {
    grid-template-columns: 15.5rem minmax(0, 1fr) 16.5rem;
    align-items: start;
    padding: 1.5rem 1.5rem 3rem;
    gap: 1.25rem;
  }

  .side-left,
  .side-right {
    position: sticky;
    top: 4.25rem;
    max-height: calc(100vh - 5rem);
    overflow-y: auto;
    align-self: start;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.play-panel {
  padding: 1rem;
}

@media (min-width: 640px) {
  .play-panel {
    padding: 1.25rem 1.35rem 1.5rem;
  }
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.9rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
}

.pill.accent {
  background: var(--tide-50);
  border-color: color-mix(in srgb, var(--tide-500) 35%, var(--border));
  color: var(--tide-800);
}

html.night-tide .pill.accent {
  background: rgba(42, 157, 143, 0.15);
  color: var(--tide-200);
}

.tagline {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.85rem;
}

/* Board */
.board-wrap {
  display: flex;
  justify-content: center;
  touch-action: manipulation;
}

.board {
  --cell: min(9.6vw, 3.15rem);
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  grid-template-rows: repeat(9, var(--cell));
  gap: 0;
  border: 2.5px solid var(--grid-box);
  border-radius: 0.85rem;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset;
  user-select: none;
  -webkit-user-select: none;
}

@media (min-width: 640px) {
  .board {
    --cell: 3.35rem;
  }
}

@media (min-width: 960px) {
  .board {
    --cell: 3.55rem;
  }
}

body.large-type .board {
  --cell: min(10.5vw, 3.65rem);
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.48);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--entry);
  background: var(--surface);
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  cursor: pointer;
  outline: none;
  transition: background 0.12s ease;
}

.cell:nth-child(9n) {
  border-right: none;
}
.cell:nth-child(n + 73) {
  border-bottom: none;
}
/* box borders */
.cell:nth-child(3n):not(:nth-child(9n)) {
  border-right: 2px solid var(--grid-box);
}
.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--grid-box);
}

.cell.given {
  color: var(--given);
  font-weight: 700;
}

.cell.related {
  background: var(--cell-related);
}
.cell.same-num {
  background: var(--cell-same);
}
.cell.selected {
  background: var(--cell-selected);
  box-shadow: inset 0 0 0 2px var(--tide-500);
  z-index: 1;
}
.cell.conflict {
  color: var(--conflict);
  background: color-mix(in srgb, var(--conflict) 12%, var(--surface));
}
.cell:hover:not(.selected) {
  background: var(--cell-hover);
}
.cell.flash {
  animation: cell-pulse 0.55s ease;
}
.cell.hint-glow {
  box-shadow: inset 0 0 0 2px var(--tide-500);
  background: color-mix(in srgb, var(--tide-200) 45%, var(--surface));
}

@keyframes cell-pulse {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

.board.solved {
  animation: board-tide 1.1s ease;
}

@keyframes board-tide {
  0% {
    box-shadow: 0 0 0 0 rgba(42, 157, 143, 0.35);
  }
  60% {
    box-shadow: 0 0 0 14px rgba(42, 157, 143, 0);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

/* Notes */
.notes {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: calc(var(--cell) * 0.18);
  font-weight: 500;
  color: var(--note);
  line-height: 1;
  pointer-events: none;
}

.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
}

.notes span.on {
  color: var(--tide-700);
  font-weight: 600;
}

html.night-tide .notes span.on {
  color: var(--tide-200);
}

/* Ocean icons mode */
.cell.icons {
  font-size: calc(var(--cell) * 0.42);
}

/* Number pad */
.pad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0.4rem;
  margin-top: 1rem;
}

.pad #pad-clear {
  grid-column: 1 / -1;
  min-height: 2.4rem;
  font-size: 0.85rem;
}

.pad button,
.tool-btn,
.btn {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 0.75rem;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}

.pad button:active,
.tool-btn:active,
.btn:active {
  transform: scale(0.97);
}

.pad button {
  min-height: 2.75rem;
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.pad button:hover,
.tool-btn:hover {
  background: var(--tide-50);
  border-color: color-mix(in srgb, var(--tide-500) 30%, var(--border));
}

html.night-tide .pad button:hover,
html.night-tide .tool-btn:hover {
  background: rgba(42, 157, 143, 0.12);
}

.pad button.active-num {
  background: var(--tide-700);
  border-color: var(--tide-700);
  color: #fff;
}

.tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.tool-btn {
  min-height: 2.65rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.25rem;
}

.tool-btn i {
  font-size: 0.95rem;
  color: var(--tide-700);
}

html.night-tide .tool-btn i {
  color: var(--tide-200);
}

.tool-btn.on {
  background: var(--tide-700);
  border-color: var(--tide-700);
  color: #fff;
}

.tool-btn.on i {
  color: #fff;
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Side panel */
.side {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.side .panel {
  padding: 1rem 1.1rem;
}

.side h2 {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
}

.side p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.diff-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.diff-btn {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-radius: 0.85rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
}

.diff-btn strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.1rem;
}

.diff-btn span {
  font-size: 0.75rem;
  color: var(--muted);
}

.diff-btn:hover,
.diff-btn.active {
  border-color: color-mix(in srgb, var(--tide-500) 40%, var(--border));
  background: var(--tide-50);
}

html.night-tide .diff-btn:hover,
html.night-tide .diff-btn.active {
  background: rgba(42, 157, 143, 0.12);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.55rem 0.65rem;
}

.stat b {
  display: block;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  color: var(--tide-700);
}

html.night-tide .stat b {
  color: var(--tide-200);
}

.stat span {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child {
  border-bottom: none;
}

.switch {
  position: relative;
  width: 2.5rem;
  height: 1.4rem;
  border-radius: 999px;
  background: var(--border);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.switch[aria-checked="true"] {
  background: var(--tide-600);
}

.switch[aria-checked="true"]::after {
  transform: translateX(1.1rem);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

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

.btn-primary:hover {
  background: var(--tide-800);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-soft {
  background: var(--tide-50);
  border-color: color-mix(in srgb, var(--tide-500) 30%, var(--border));
  color: var(--tide-800);
}

html.night-tide .btn-soft {
  background: rgba(42, 157, 143, 0.15);
  color: var(--tide-100);
}

.icon-btn {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--tide-50);
}

/* Modal */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 34, 32, 0.45);
  backdrop-filter: blur(6px);
}

.modal-root.open {
  display: flex;
}

.modal {
  width: min(100%, 26rem);
  background: var(--surface);
  color: var(--ink);
  border-radius: 1.35rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.35rem 1.25rem;
  max-height: min(90vh, 40rem);
  overflow: auto;
  position: relative;
}

.modal h2 {
  font-family: var(--display);
  font-size: 1.85rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  line-height: 1.15;
}

.modal .line {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.fact-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.fact-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tide-600);
}

html.night-tide .fact-card h3 {
  color: var(--tide-200);
}

.fact-card p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
}

.next-block {
  margin: 0 0 0.9rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.9rem;
}

.next-label {
  margin: 0 0 0.45rem;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--tide-600);
}

html.night-tide .next-label {
  color: var(--tide-200);
}

.next-games {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.next-games a {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.55rem 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  transition: border-color 0.15s, background 0.15s;
}

.next-games a:hover {
  border-color: color-mix(in srgb, var(--tide-500) 45%, var(--border));
  background: color-mix(in srgb, var(--tide-500) 8%, var(--surface));
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Loading splash */
.splash {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--sand-50);
  transition: opacity 0.4s ease, visibility 0.4s;
}

.splash.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash p {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  color: var(--tide-800);
}

.splash span {
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.footer-mini {
  text-align: center;
  padding: 0.5rem 1rem 1.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.footer-mini a {
  color: var(--tide-700);
  text-decoration: none;
  font-weight: 600;
}

html.night-tide .footer-mini a {
  color: var(--tide-200);
}

/* Progress water visual */
.water-meter {
  height: 0.45rem;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 0.65rem;
}

.water-meter > i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--tide-500), var(--tide-700));
  transition: width 0.45s ease;
}

.milestone {
  font-size: 0.78rem;
  color: var(--tide-700);
  margin-top: 0.45rem;
  font-weight: 500;
}

html.night-tide .milestone {
  color: var(--tide-200);
}

.complete-ripple {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 0 rgba(42, 157, 143, 0.35);
  animation: ripple-in 1.2s ease forwards;
}

@keyframes ripple-in {
  to {
    box-shadow: inset 0 0 40px 8px rgba(42, 157, 143, 0.12);
  }
}
