/* Tide Mahjong — calm solitaire */

:root,
html.day-tide {
  --bg: #f4f1eb;
  --bg2: #eaf4f1;
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --border: #e2d9cc;
  --text: #0f332f;
  --muted: rgba(15, 51, 47, 0.55);
  --tide-500: #2a9d8f;
  --tide-600: #1f7a6f;
  --tide-700: #1a6158;
  --tide-200: #a8e0d4;
  --tile-face: #faf8f4;
  --tile-edge: #d4c9b8;
  --tile-free: #e8f6f2;
  --tile-sel: #c5ebe3;
  --shadow: 0 16px 44px -26px rgba(15, 51, 47, 0.28);
  --font: Inter, system-ui, sans-serif;
  --display: "Cormorant Garamond", Georgia, serif;
  --radius: 1.2rem;
  --tw: 2.85rem;
  --th: 3.45rem;
}

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);
  --tile-face: #1a403a;
  --tile-edge: #2a5c54;
  --tile-free: #1f4f48;
  --tile-sel: #2a6b60;
  --shadow: 0 18px 48px -18px rgba(0, 0, 0, 0.55);
}

html.large-tiles {
  --tw: 3.25rem;
  --th: 3.95rem;
}

html.high-contrast {
  --tile-face: #fffef9;
  --tile-edge: #0f332f;
  --tile-free: #d0f0e8;
  --text: #06201c;
}

*,
*::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 85% 50% at 50% 30%, rgba(42, 157, 143, 0.09), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg2));
}

.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) 90%, 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.15rem;
  font-weight: 600;
}

.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-ghost {
  background: transparent;
}

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

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

/* Left = Comfort · center = board · right = modes/progress */
.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) 16rem;
    gap: 1.1rem;
    padding: 1.25rem 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.05rem 1rem 1.3rem;
}

.tagline {
  margin: 0 0 0.8rem;
  font-size: 0.88rem;
  color: var(--muted);
  max-width: 40rem;
}

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

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

.pill {
  display: inline-flex;
  align-items: center;
  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);
}

.board-shell {
  display: flex;
  justify-content: center;
  overflow: auto;
  padding: 1.25rem 0.5rem 1.35rem;
  min-height: 18rem;
  -webkit-user-select: none;
  user-select: none;
  background: linear-gradient(180deg, transparent, rgba(42, 157, 143, 0.04));
  border-radius: 1rem;
}

.board {
  position: relative;
  margin: 0 auto;
}

.tile {
  position: absolute;
  width: var(--tw);
  height: var(--th);
  border: none;
  padding: 0.15rem;
  border-radius: 0.55rem;
  /* Solid fill first — never transparent so under-tiles cannot show through */
  background-color: #faf8f4;
  background-image: linear-gradient(160deg, #ffffff 0%, #faf8f4 50%, #f0ebe3 100%);
  border: 1.5px solid var(--tile-edge);
  box-shadow:
    2px 3px 0 rgba(15, 51, 47, 0.12),
    3px 5px 0 rgba(15, 51, 47, 0.06),
    0 8px 14px -8px rgba(15, 51, 47, 0.35);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  opacity: 1;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.35s ease, filter 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  isolation: isolate;
  overflow: hidden;
}

html.night-tide .tile {
  background-color: #1a403a;
  background-image: linear-gradient(160deg, #2a524c 0%, #1a403a 55%, #12352f 100%);
}

.tile .icon {
  font-size: calc(var(--tw) * 0.42);
  line-height: 1;
  color: var(--tide-700);
}

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

.tile .label {
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile.free {
  background-color: #e8f6f2;
  background-image: linear-gradient(160deg, #ffffff 0%, #e8f6f2 100%);
  border-color: color-mix(in srgb, var(--tide-500) 45%, var(--tile-edge));
  opacity: 1;
  filter: none;
}

html.night-tide .tile.free {
  background-color: #1f4f48;
  background-image: linear-gradient(160deg, #2a5c54 0%, #1f4f48 100%);
}

/* Blocked tiles stay fully opaque — only tint, never fade through */
.tile.blocked {
  opacity: 1;
  filter: none;
  cursor: default;
  background-color: #ebe6de;
  background-image: linear-gradient(160deg, #f5f2ec 0%, #e5e0d6 100%);
  border-color: #cfc6b8;
  color: rgba(15, 51, 47, 0.55);
}

html.night-tide .tile.blocked {
  background-color: #163832;
  background-image: linear-gradient(160deg, #1c403a 0%, #14302c 100%);
  border-color: #2a4a44;
  color: rgba(232, 245, 242, 0.55);
}

.tile.blocked .icon {
  opacity: 0.55;
}

.tile.blocked .label {
  opacity: 0.5;
}

.tile.selected {
  background-color: #c5ebe3;
  background-image: linear-gradient(160deg, #ffffff 0%, #c5ebe3 100%);
  box-shadow:
    0 0 0 3px color-mix(in srgb, #5ec8c0 55%, transparent),
    0 8px 16px -8px rgba(15, 51, 47, 0.4);
  transform: translateY(-3px);
  z-index: 1000 !important;
  opacity: 1;
}

html.night-tide .tile.selected {
  background-color: #2a6b60;
  background-image: linear-gradient(160deg, #3a7a6e 0%, #2a6b60 100%);
}

.tile.hint {
  box-shadow:
    0 0 0 3px color-mix(in srgb, #5ec8c0 70%, transparent),
    0 0 12px rgba(94, 200, 192, 0.45);
  z-index: 900 !important;
  animation: hint-soft 1.2s ease infinite alternate;
}

@keyframes hint-soft {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-2px);
  }
}

.tile.removing {
  opacity: 0;
  transform: translateY(-12px) scale(0.92);
  pointer-events: none;
}

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

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

.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;
  transition: transform 0.15s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

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

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

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

.status-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.35rem 0 0;
  min-height: 1.2em;
}

@media (max-width: 480px) {
  :root {
    --tw: 2.45rem;
    --th: 3rem;
  }
  html.large-tiles {
    --tw: 2.75rem;
    --th: 3.35rem;
  }
  .tile .label {
    font-size: 0.48rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile.removing {
    transition: none !important;
  }
}
