:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --bg: #f7f8f4;
  --text: #18221d;
  --muted: #5d665f;
  --surface: #ffffff;
  --surface-strong: #f1f5ee;
  --line: rgba(24, 34, 29, 0.16);
  --accent: #d9534f;
  --accent-2: #2f7d6d;
  --accent-3: #e0ad32;
  --tile-overlay: rgba(10, 14, 12, 0.56);
  --shadow: 0 22px 70px rgba(23, 30, 25, 0.2);
  --soft-shadow: 0 10px 30px rgba(23, 30, 25, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

body.is-locked {
  overflow: hidden;
}

button,
audio {
  font: inherit;
}

button {
  cursor: pointer;
}

.passcode-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(rgba(247, 248, 244, 0.78), rgba(247, 248, 244, 0.9)),
    url("assets/images/koans/01-today-special-day.jpg") center / cover;
}

.passcode-screen[hidden] {
  display: none;
}

.passcode-card {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 24px;
}

.passcode-kicker {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.passcode-card h2 {
  margin: 0 0 22px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  line-height: 1;
}

.passcode-card label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.passcode-row {
  display: flex;
  gap: 10px;
}

.passcode-row input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  padding: 0 12px;
}

.passcode-submit {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-weight: 800;
  padding: 0 16px;
}

.passcode-error {
  min-height: 1.3em;
  margin: 10px 0 0;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
}

body.is-locked .app-shell,
body.is-locked .overlay {
  filter: blur(8px);
  pointer-events: none;
  user-select: none;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

.brand {
  min-width: 0;
}

.kicker {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 0.82rem;
  font-weight: 750;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 3.3rem;
  font-weight: 700;
  line-height: 0.95;
}

.definition-card {
  width: min(430px, 44vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface), var(--surface-strong) 28%);
  box-shadow: 0 10px 24px rgba(23, 30, 25, 0.08);
  padding: 14px;
}

.dictionary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.dictionary-word {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  font-weight: 750;
}

.pronunciation {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.part-of-speech {
  border-left: 1px solid var(--line);
  color: var(--accent-2);
  padding-left: 8px;
  font-size: 0.78rem;
  font-style: italic;
  font-weight: 750;
}

.definition-card p {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.98rem;
  line-height: 1.34;
}

.play-all,
.nav-button,
.close-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}

.play-all,
.nav-button {
  padding: 0 14px;
  font-size: 0.9rem;
  font-weight: 750;
}

.play-all {
  width: 100%;
  border-color: transparent;
  background: var(--text);
  color: var(--surface);
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--surface-strong);
  box-shadow: var(--soft-shadow);
  transform: translateZ(0);
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--tile-image);
  background-position: center;
  background-size: cover;
  transform: scale(1.02);
  transition: transform 260ms ease;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.24)),
    var(--tile-overlay);
  transition: opacity 220ms ease;
}

.tile:hover::before,
.tile:focus-visible::before {
  transform: scale(1.075);
}

.tile:hover::after,
.tile:focus-visible::after {
  opacity: 0.86;
}

.tile:focus-visible,
.play-all:focus-visible,
.passcode-row input:focus-visible,
.passcode-submit:focus-visible,
.nav-button:focus-visible,
.close-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent-3), white 16%);
  outline-offset: 3px;
}

.tile-content {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
  color: #fff;
  text-align: left;
}

.tile-number,
.tile-duration,
.detail-number,
.detail-duration {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.tile-number {
  color: rgba(255, 255, 255, 0.78);
}

.tile-title {
  margin: 0;
  max-width: 14rem;
  font-size: 1.18rem;
  font-weight: 850;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.tile-duration {
  color: rgba(255, 255, 255, 0.72);
}

.tile.is-launching {
  animation: tile-pop 260ms ease both;
}

@keyframes tile-pop {
  50% {
    transform: scale(0.97) rotateY(8deg);
  }
  100% {
    transform: scale(1);
  }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(5, 7, 6, 0.76);
}

.detail {
  position: relative;
  z-index: 1;
  width: min(880px, 100%);
  perspective: 1800px;
}

.detail-card {
  position: relative;
  min-height: 520px;
  transform-style: preserve-3d;
  transform: rotateY(0deg) scale(0.96);
  opacity: 0;
  transition:
    transform 520ms cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 180ms ease;
}

.overlay.is-open .detail-card {
  transform: rotateY(180deg) scale(1);
  opacity: 1;
}

.detail-face {
  position: absolute;
  inset: 0;
  display: grid;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--line), white 14%);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
}

.detail-front {
  place-items: center;
  padding: 32px;
  text-align: center;
}

.detail-front h2 {
  max-width: 660px;
  margin: 14px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 3rem;
  line-height: 1;
}

.detail-number,
.detail-duration {
  color: var(--accent-2);
}

.detail-back {
  grid-template-columns: minmax(260px, 0.92fr) minmax(300px, 1fr);
  transform: rotateY(180deg);
}

.detail-image {
  width: 100%;
  height: 100%;
  min-height: 520px;
  object-fit: contain;
  object-position: center;
  background: #0b0d0b;
}

.detail-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 36px;
  background: var(--surface);
}

.detail-heading {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.35rem;
  line-height: 1.02;
}

.player {
  width: 100%;
  min-height: 42px;
}

.detail-nav {
  display: flex;
  gap: 10px;
}

.nav-button {
  flex: 1;
}

.close-button {
  position: absolute;
  top: -14px;
  right: -14px;
  z-index: 3;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.8rem;
  line-height: 1;
}

body[data-theme="keepsake"] {
  --bg: #f5f7f0;
  --text: #223126;
  --muted: #687064;
  --surface: #fffdf7;
  --surface-strong: #eef3e8;
  --line: rgba(34, 49, 38, 0.18);
  --accent: #bc4d3f;
  --accent-2: #527d42;
  --accent-3: #d2a23a;
  --tile-overlay: rgba(33, 48, 38, 0.48);
  --shadow: 0 24px 70px rgba(48, 49, 34, 0.22);
  --soft-shadow: 0 12px 24px rgba(48, 49, 34, 0.12);
}

body[data-theme="keepsake"] .tile {
  padding: 8px;
  background: var(--surface);
}

body[data-theme="keepsake"] .tile::before,
body[data-theme="keepsake"] .tile::after {
  inset: 8px;
  border-radius: 5px;
}

body[data-theme="keepsake"] .tile-content {
  inset: 8px;
}

body[data-theme="keepsake"] .tile-title {
  padding: 8px 9px;
  background: rgba(255, 253, 247, 0.9);
  color: var(--text);
  box-decoration-break: clone;
}

body[data-theme="keepsake"] .tile-number,
body[data-theme="keepsake"] .tile-duration {
  color: rgba(255, 255, 255, 0.82);
}

body[data-theme="theater"] {
  color-scheme: dark;
  --bg: #10100f;
  --text: #f6f1e7;
  --muted: #c8bfae;
  --surface: #1d1c1a;
  --surface-strong: #24231f;
  --line: rgba(246, 241, 231, 0.17);
  --accent: #f0724e;
  --accent-2: #70bfa5;
  --accent-3: #f1bd51;
  --tile-overlay: rgba(10, 10, 9, 0.62);
  --shadow: 0 24px 86px rgba(0, 0, 0, 0.58);
  --soft-shadow: 0 14px 34px rgba(0, 0, 0, 0.34);
}

body[data-theme="theater"] .mode-button,
body[data-theme="theater"] .nav-button,
body[data-theme="theater"] .close-button {
  background: #262520;
  color: var(--text);
}

body[data-theme="theater"] .play-all,
body[data-theme="theater"] .mode-button.is-active {
  background: #f1bd51;
  color: #17130c;
}

body[data-theme="theater"] .tile {
  border-color: rgba(241, 189, 81, 0.32);
}

body[data-theme="theater"] .tile::after {
  background:
    linear-gradient(180deg, rgba(240, 114, 78, 0.12), rgba(0, 0, 0, 0.32)),
    var(--tile-overlay);
}

@media (max-width: 900px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .definition-card {
    width: 100%;
  }

  .tile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-back {
    grid-template-columns: 1fr;
  }

  .detail,
  .detail-card,
  .detail-face {
    min-height: min(780px, calc(100vh - 40px));
  }

  .detail-image {
    min-height: 300px;
    height: 42vh;
  }

  .detail-copy {
    justify-content: flex-start;
    padding: 24px;
  }
}

@media (max-width: 560px) {
  .passcode-row {
    flex-direction: column;
  }

  .passcode-submit {
    width: 100%;
  }

  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  h1 {
    font-size: 2.45rem;
  }

  .play-all {
    width: 100%;
    padding: 0 10px;
  }

  .tile-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .tile-content {
    padding: 14px;
  }

  .tile-title {
    font-size: 1.12rem;
  }

  .overlay {
    padding: 10px;
  }

  .detail-front h2,
  .detail-heading {
    font-size: 2rem;
  }

  .close-button {
    top: 8px;
    right: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .overlay.is-open .detail-card {
    transform: scale(1);
  }

  .detail-back {
    transform: none;
  }

  .detail-front {
    display: none;
  }
}
