/* Clear Water — meditative water-sort UI */

:root,
html.day-tide {
  --bg: #f7f4ef;
  --bg2: #eef6f4;
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --border: #e5ddd0;
  --text: #0f332f;
  --muted: rgba(15, 51, 47, 0.55);
  --tide-500: #2a9d8f;
  --tide-600: #1f7a6f;
  --tide-700: #1a6158;
  --tide-200: #a8e0d4;
  --glass: rgba(255, 255, 255, 0.55);
  --glass-edge: rgba(15, 51, 47, 0.12);
  --shadow: 0 18px 50px -28px rgba(15, 51, 47, 0.25);
  --font: Inter, system-ui, sans-serif;
  --display: "Cormorant Garamond", Georgia, serif;
  --radius: 1.25rem;
  --bottle-w: 3.35rem;
  --bottle-h: 9.5rem;
  --layer-h: 1.85rem;
}

html.night-tide {
  --bg: #0a2220;
  --bg2: #0f332f;
  --surface: #12352f;
  --surface-2: #164e47;
  --border: rgba(168, 224, 212, 0.16);
  --text: #e8f5f2;
  --muted: rgba(232, 245, 242, 0.55);
  --glass: rgba(15, 51, 47, 0.35);
  --glass-edge: rgba(168, 224, 212, 0.28);
  --shadow: 0 18px 48px -18px rgba(0, 0, 0, 0.55);
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

.bg-wash {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 45% at 50% 0%, rgba(42, 157, 143, 0.1), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}

html.night-tide .bg-wash {
  background:
    radial-gradient(ellipse 70% 40% at 50% -5%, rgba(42, 157, 143, 0.16), transparent 50%),
    linear-gradient(180deg, #071816, #0a2220 60%, #0f332f);
}

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

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

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: inherit;
}

.brand img {
  height: 1.8rem;
  width: auto;
}

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

.brand span {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

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

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

.icon-btn {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.95rem;
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: 999px;
}

.btn-sm {
  min-height: 2.15rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.78rem;
}

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

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover,
.icon-btn:hover {
  background: color-mix(in srgb, var(--tide-500) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--tide-500) 30%, var(--border));
}

.main {
  flex: 1;
  width: 100%;
  max-width: 88rem;
  margin: 0 auto;
  padding: 1rem 0.85rem 2rem;
  display: grid;
  gap: 1rem;
}

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

@media (min-width: 1100px) {
  .main {
    grid-template-columns: 15rem minmax(0, 1fr) 16rem;
    gap: 1.1rem;
    padding: 1.35rem 1.25rem 2.5rem;
    align-items: start;
  }

  .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: 1.15rem 1rem 1.4rem;
}

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

.tagline {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
  color: var(--muted);
  max-width: 36rem;
}

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

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.32rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.pill.accent {
  background: color-mix(in srgb, var(--tide-500) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--tide-500) 30%, var(--border));
  color: var(--tide-700);
}

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

/* Bottle board */
.board-shell {
  display: flex;
  justify-content: center;
  padding: 1.25rem 0.5rem 0.5rem;
  min-height: 14rem;
}

.board {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 0.85rem 1rem;
  max-width: 36rem;
}

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

@keyframes tide-wash {
  0% {
    filter: brightness(1);
  }
  40% {
    filter: brightness(1.08);
  }
  100% {
    filter: brightness(1);
  }
}

.bottle-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.bottle {
  --cap: 4;
  width: var(--bottle-w);
  height: var(--bottle-h);
  position: relative;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bottle:focus-visible {
  outline: 2px solid var(--tide-500);
  outline-offset: 4px;
  border-radius: 0.5rem;
}

.bottle-glass {
  position: absolute;
  inset: 0;
  border-radius: 0.55rem 0.55rem 1.1rem 1.1rem;
  background: linear-gradient(
    160deg,
    rgba(255, 255, 255, 0.35) 0%,
    rgba(255, 255, 255, 0.08) 40%,
    rgba(15, 51, 47, 0.04) 100%
  );
  border: 1.5px solid var(--glass-edge);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.25),
    0 8px 18px -12px rgba(15, 51, 47, 0.35);
  overflow: hidden;
}

html.night-tide .bottle-glass {
  background: linear-gradient(
    160deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(10, 34, 32, 0.4) 100%
  );
}

.bottle-neck {
  position: absolute;
  top: -0.45rem;
  left: 50%;
  transform: translateX(-50%);
  width: 42%;
  height: 0.55rem;
  border-radius: 0.25rem 0.25rem 0 0;
  background: color-mix(in srgb, var(--surface) 70%, var(--tide-200));
  border: 1px solid var(--glass-edge);
  border-bottom: none;
  z-index: 2;
}

.layers {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  height: calc(100% - 10px);
  display: flex;
  flex-direction: column-reverse;
  border-radius: 0 0 0.95rem 0.95rem;
  overflow: hidden;
}

.layer {
  width: 100%;
  flex: 0 0 auto;
  height: calc(100% / var(--cap, 4));
  transition: height 0.35s ease, background 0.2s ease;
  position: relative;
}

.layer::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 35%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent);
  pointer-events: none;
}

.bottle.selected .bottle-glass {
  border-color: var(--tide-500);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.3),
    0 0 0 3px color-mix(in srgb, var(--tide-500) 28%, transparent),
    0 10px 22px -12px rgba(15, 51, 47, 0.4);
  transform: translateY(-4px);
}

.bottle.selected .bottle-neck {
  transform: translateX(-50%) translateY(-4px);
}

.bottle.pour-from .bottle-glass {
  transform: translateY(-10px) rotate(-6deg);
  transition: transform 0.28s ease;
}

.bottle.pour-to .layer:last-child {
  animation: ripple-land 0.45s ease;
}

@keyframes ripple-land {
  0% {
    filter: brightness(1.15);
  }
  100% {
    filter: brightness(1);
  }
}

.bottle.invalid {
  animation: soft-shake 0.35s ease;
}

@keyframes soft-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-3px);
  }
  60% {
    transform: translateX(3px);
  }
}

.bottle-label {
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: 600;
}

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

.tool-btn {
  min-height: 2.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.35rem;
}

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

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

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

.side {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

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

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

.side p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
}

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

.mode-btn {
  text-align: left;
  padding: 0.65rem 0.8rem;
  border-radius: 0.85rem;
}

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

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

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

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

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.5rem 0.6rem;
}

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

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

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

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

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

.switch {
  width: 2.45rem;
  height: 1.35rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--border);
  position: relative;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

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

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

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

.footer-mini {
  text-align: center;
  padding: 0.35rem 1rem 1.2rem;
  font-size: 0.74rem;
  color: var(--muted);
}

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

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

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 51, 47, 0.3);
  backdrop-filter: blur(6px);
}

html.night-tide .modal-root {
  background: rgba(5, 16, 14, 0.55);
}

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

.modal {
  width: min(100%, 25rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 1.4rem 1.25rem 1.2rem;
  box-shadow: var(--shadow);
}

.modal .kicker {
  margin: 0 0 0.3rem;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--tide-600);
}

.modal h2 {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-size: 1.75rem;
  font-weight: 600;
}

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

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

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

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

.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);
}

.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(--text);
  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));
}

.btn-soft {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-soft:hover {
  background: color-mix(in srgb, var(--tide-500) 10%, var(--surface-2));
}

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

.splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  background: var(--bg);
  transition: opacity 0.4s, visibility 0.4s;
}

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

.splash p {
  margin: 0;
  font-family: var(--display);
  font-size: 1.5rem;
}

.splash span {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

@media (max-width: 480px) {
  :root {
    --bottle-w: 2.85rem;
    --bottle-h: 8.4rem;
  }
  .board {
    gap: 0.7rem 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .layer,
  .bottle.selected .bottle-glass,
  .bottle.pour-from .bottle-glass,
  .board.solved,
  .layer::after {
    transition: none !important;
    animation: none !important;
  }
}
