/* Leo's Letter Quest — notebook-themed styles */
@font-face {
  font-family: "Caveat";
  src: url("../assets/fonts/caveat-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Caveat";
  src: url("../assets/fonts/caveat-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Baloo 2";
  src: url("../assets/fonts/baloo-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Baloo 2";
  src: url("../assets/fonts/baloo-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Baloo 2";
  src: url("../assets/fonts/baloo-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #fdf6e3;
  --paper-2: #f8efd8;
  --ink: #1e3a8a;
  --ink-soft: #3b5bb5;
  --marker: #2563eb;
  --accent: #ef4444;
  --gold: #d97706;
  --gold-bg: #fef3c7;
  --shadow: rgba(60, 42, 13, 0.18);
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  font-family: "Baloo 2", "Comic Sans MS", system-ui, sans-serif;
  color: var(--ink);
  touch-action: manipulation;
}

#app {
  height: 100dvh;
  width: 100vw;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.screen.active {
  display: flex;
}

/* ---------- buttons ---------- */
.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  background: #fffdf4;
  border: 3px solid var(--ink-soft);
  border-radius: 16px;
  padding: 0.55em 1.1em;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  user-select: none;
}
.btn:hover {
  filter: brightness(1.03);
}
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--shadow);
}
.btn.primary {
  background: var(--marker);
  color: #fff;
  border-color: #1e40af;
}
.btn.big {
  font-size: 1.25rem;
  padding: 0.6em 1.4em;
}
.btn.icon-btn {
  padding: 0.4em 0.6em;
  font-size: 1.1rem;
  border-width: 2px;
}
.btn.tool {
  font-size: 0.95rem;
  border-width: 2px;
}

/* ---------- inline SVG icons (masked, inherit text color) ---------- */
.icon {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
  vertical-align: -0.18em;
}
.i-play { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M8 5v14l11-7z'/%3E%3C/svg%3E"); }
.i-grid { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23000'%3E%3Crect x='4' y='4' width='7' height='7' rx='1.5'/%3E%3Crect x='13' y='4' width='7' height='7' rx='1.5'/%3E%3Crect x='4' y='13' width='7' height='7' rx='1.5'/%3E%3Crect x='13' y='13' width='7' height='7' rx='1.5'/%3E%3C/g%3E%3C/svg%3E"); }
.i-book { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='4' y='3' width='16' height='18' rx='2.5' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath d='M8 8h8M8 12h8M8 16h5' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.i-pause { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23000'%3E%3Crect x='6' y='4' width='4' height='16' rx='1.5'/%3E%3Crect x='14' y='4' width='4' height='16' rx='1.5'/%3E%3C/g%3E%3C/svg%3E"); }
.i-vol { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23000'%3E%3Cpath d='M4 9v6h4l5 4V5L8 9z'/%3E%3C/g%3E%3Cpath d='M16 8.5a5 5 0 0 1 0 7M18.5 6a8.5 8.5 0 0 1 0 12' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.i-mute { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23000'%3E%3Cpath d='M4 9v6h4l5 4V5L8 9z'/%3E%3C/g%3E%3Cpath d='M16 9l6 6M22 9l-6 6' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.i-bulb { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23000'%3E%3Cpath d='M12 2a7 7 0 0 0-4 12.7c.6.5 1 1.2 1 2v.8h6v-.8c0-.8.4-1.5 1-2A7 7 0 0 0 12 2z'/%3E%3Crect x='9.5' y='19' width='5' height='2' rx='1'/%3E%3C/g%3E%3C/svg%3E"); }
.i-dice { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='3' y='3' width='18' height='18' rx='4' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cg fill='%23000'%3E%3Ccircle cx='8' cy='8' r='1.6'/%3E%3Ccircle cx='16' cy='8' r='1.6'/%3E%3Ccircle cx='12' cy='12' r='1.6'/%3E%3Ccircle cx='8' cy='16' r='1.6'/%3E%3Ccircle cx='16' cy='16' r='1.6'/%3E%3C/g%3E%3C/svg%3E"); }
.i-home { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 3l9 8h-2v9h-5v-6h-4v6H5v-9H3z'/%3E%3C/svg%3E"); }
.i-bolt { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M13 2L4 14h6l-1 8 9-12h-6z'/%3E%3C/svg%3E"); }
.i-lock { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='5' y='11' width='14' height='10' rx='2' fill='%23000'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3' fill='none' stroke='%23000' stroke-width='2.5'/%3E%3C/svg%3E"); }
.i-trophy { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23000'%3E%3Cpath d='M6 3h12v2h3v2c0 2.8-1.6 5-4.5 5h-.7A6 6 0 0 1 13 14.7V17h3v3H8v-3h3v-2.3A6 6 0 0 1 8.2 12h-.7C4.6 12 3 9.8 3 7V5h3z'/%3E%3C/g%3E%3C/svg%3E"); }
.i-back { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 11H7.8l5.6-5.6L12 4l-8 8 8 8 1.4-1.4L7.8 13H20z' fill='%23000'/%3E%3C/svg%3E"); }
.i-next { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 11H7.8l5.6-5.6L12 4l-8 8 8 8 1.4-1.4L7.8 13H20z' fill='%23000'/%3E%3C/svg%3E"); transform: rotate(180deg); }
.i-refresh { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 5V2L7 6l5 4V7a5 5 0 1 1-5 5H5a7 7 0 1 0 7-7z' fill='%23000'/%3E%3C/svg%3E"); }

/* ---------- title ---------- */
#screen-title {
  background: url("../assets/img/hero.jpg") center / cover no-repeat;
}
#screen-title::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(253, 246, 227, 0) 30%, rgba(253, 246, 227, 0.65) 100%);
  pointer-events: none;
}
#tile3d-canvas {
  position: absolute;
  top: 4%;
  left: 50%;
  transform: translateX(-50%);
  width: min(44vw, 300px);
  height: min(30vh, 240px);
  z-index: 2;
  pointer-events: none;
}
.title-inner {
  position: relative;
  z-index: 3;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  padding: 1rem;
  margin-top: max(26vh, 180px);
}
.logo {
  font-family: "Caveat", cursive;
  font-size: clamp(2.4rem, 9vw, 4.2rem);
  font-weight: 700;
  color: var(--ink);
  text-shadow: 3px 3px 0 rgba(255, 255, 255, 0.8);
  line-height: 1.05;
}
.logo span {
  color: var(--accent);
}
.tagline {
  font-size: clamp(0.95rem, 3.4vw, 1.2rem);
  color: #37416b;
  background: rgba(255, 253, 244, 0.75);
  border-radius: 999px;
  padding: 0.2em 1em;
}
.title-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
}
.title-foot {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.95rem;
  background: rgba(255, 253, 244, 0.8);
  border-radius: 999px;
  padding: 0.3em 0.9em;
}

/* ---------- generic page / card ---------- */
.page {
  width: min(680px, 94vw);
  max-height: 92dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.2rem;
}
.card {
  background:
    linear-gradient(rgba(253, 246, 227, 0.94), rgba(253, 246, 227, 0.94)),
    url("../assets/img/paper.jpg") center / cover;
  border: 3px solid var(--ink-soft);
  border-radius: 20px;
  box-shadow: 0 8px 24px var(--shadow);
}
.ink-title {
  font-family: "Caveat", cursive;
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  color: var(--ink);
  text-decoration: underline wavy var(--marker) 2px;
  text-underline-offset: 6px;
}
.howto-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-left: 1.2rem;
  font-size: 1.02rem;
  line-height: 1.35;
}

/* Leo's table */
.leo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.55);
  border: 3px double var(--ink-soft);
}
.leo-table th,
.leo-table td {
  border: 2px solid var(--ink-soft);
  padding: 0.22em 0.4em;
  text-align: center;
}
.leo-table th {
  background: rgba(37, 99, 235, 0.12);
}
.leo-table .mono {
  font-family: ui-monospace, monospace;
  letter-spacing: 0.08em;
}

/* ---------- level select ---------- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.7rem;
  width: 100%;
}
@media (min-width: 640px) {
  .level-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
.level-cell {
  position: relative;
  font-family: inherit;
  background: #fffdf4;
  border: 3px solid var(--ink-soft);
  border-radius: 16px;
  padding: 0.5rem 0.2rem 0.35rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow);
  transition: transform 0.06s ease;
  color: var(--ink);
}
.level-cell:active {
  transform: translateY(3px);
}
.level-cell .ls-level {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}
.level-cell .ls-letters {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  color: #6b5b2e;
}
.level-cell .ls-stars {
  font-size: 0.8rem;
  color: var(--gold);
  letter-spacing: 0.05em;
  min-height: 1.1em;
}
.level-cell .ls-poi {
  font-size: 0.72rem;
  font-weight: 600;
  color: #37416b;
}
.level-cell.mega {
  border-color: var(--gold);
  background: var(--gold-bg);
}
.level-cell.win {
  border-color: var(--accent);
  background: #fee2e2;
}
.level-cell.locked {
  filter: grayscale(0.9);
  opacity: 0.72;
  cursor: default;
}
.level-cell.done {
  box-shadow: 0 4px 0 rgba(37, 99, 235, 0.35);
}
.levels-foot {
  display: flex;
  gap: 0.7rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- game HUD ---------- */
.game-hud {
  width: min(760px, 100vw);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  flex-wrap: wrap;
}
.game-hud .chip {
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(37, 99, 235, 0.1);
  border: 2px solid var(--ink-soft);
  border-radius: 999px;
  padding: 0.12em 0.6em;
}
.progress-wrap {
  position: relative;
  flex: 1;
  min-width: 90px;
  height: 26px;
  background: rgba(37, 99, 235, 0.12);
  border: 2px solid var(--ink-soft);
  border-radius: 999px;
  overflow: hidden;
}
#hud-bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #60a5fa, var(--marker));
  border-radius: 999px;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
#hud-score {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  font-size: 0.95rem;
}
#hud-words {
  font-weight: 700;
  font-size: 0.95rem;
  background: #fffdf4;
  border: 2px solid var(--ink-soft);
  border-radius: 999px;
  padding: 0.15em 0.7em;
  white-space: nowrap;
}
#hud-combo {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
#hud-combo.show {
  opacity: 1;
  transform: scale(1);
}
.timer {
  font-weight: 700;
  font-size: 1.1rem;
  background: #fffdf4;
  border: 2px solid var(--ink-soft);
  border-radius: 999px;
  padding: 0.12em 0.7em;
}
#endless-score {
  font-weight: 700;
  font-size: 1.1rem;
  background: var(--gold-bg);
  border: 2px solid var(--gold);
  border-radius: 999px;
  padding: 0.12em 0.7em;
}

/* ---------- board ---------- */
.board-wrap {
  flex: 1;
  width: min(760px, 100vw);
  min-height: 200px;
  padding: 0.2rem;
}
#board-canvas,
#endless-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.game-tools {
  display: flex;
  gap: 0.7rem;
  padding: 0.4rem 0.6rem 0.9rem;
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 27, 25, 0.45);
  padding: 1rem;
}
.overlay.hidden {
  display: none;
}
.modal-card {
  width: min(480px, 94vw);
  background:
    linear-gradient(rgba(253, 246, 227, 0.97), rgba(253, 246, 227, 0.97)),
    url("../assets/img/paper.jpg") center / cover;
  border: 4px solid var(--ink-soft);
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  padding: 1.2rem 1.3rem;
  text-align: center;
  animation: pop-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop-in {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.modal-card h2 {
  font-family: "Caveat", cursive;
  font-size: 2.4rem;
  color: var(--ink);
}
.table-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 3px double var(--ink-soft);
  margin: 0.7rem auto;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.6);
}
.tr-cell {
  border: 2px solid var(--ink-soft);
  padding: 0.3em 0.2em;
  font-weight: 700;
}
.tr-cell.head {
  background: rgba(37, 99, 235, 0.12);
  font-size: 0.85rem;
}
.stars {
  margin: 0.4rem 0;
}
.big-stars {
  font-size: 2.2rem;
  color: var(--gold);
  letter-spacing: 0.15em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.clear-actions {
  display: flex;
  gap: 0.7rem;
  justify-content: center;
  margin-top: 0.7rem;
}
.win-emblem {
  font-size: 4rem;
  animation: bounce 1s ease infinite;
}
.win-emblem .icon {
  width: 3.4rem;
  height: 3.4rem;
  color: var(--accent);
}
@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}
.win-sub {
  color: #37416b;
  margin-top: 0.2rem;
}
.win-credit {
  font-family: "Caveat", cursive;
  font-size: 1.6rem;
  color: var(--accent);
  margin-top: 0.4rem;
}
.endless-score {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
  margin: 0.4rem 0;
}
.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-top: 0.6rem;
}

/* ---------- toast ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: 8dvh;
  transform: translateX(-50%) translateY(20px);
  z-index: 30;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 0.98rem;
  padding: 0.55em 1.2em;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 90vw;
  text-align: center;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- reduced motion ---------- */
.reduced-motion .modal-card,
.reduced-motion .win-emblem,
.reduced-motion #hud-bar {
  animation: none;
  transition: none;
}

/* landscape small screens */
@media (orientation: landscape) and (max-height: 520px) {
  .board-wrap {
    flex: 1 1 60%;
  }
  .game-hud {
    padding: 0.25rem 0.4rem;
  }
  .btn.tool {
    font-size: 0.85rem;
  }
}
