:root {
  --ink: #f3ead8;
  --ink-dim: #b9b2a3;
  --night: #1d2433;
  --dusk: #3b3f5c;
  --ember: #e8a25c;
  --river: #5f9ea8;
  --stone: #8c8597;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  position: fixed;
  inset: 0;
}

.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fade-in 1.2s ease both;
}

.scene--leaving {
  animation: fade-out 0.6s ease both;
  pointer-events: none;
}

.backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.panel {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 0 16px;
  max-width: 34rem;
}

.title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(2.4rem, 8vw, 4.5rem);
  letter-spacing: 0.04em;
  margin: 0 0 0.25em;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.35);
}

.subtitle {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--ink-dim);
  font-size: clamp(1rem, 2.6vw, 1.25rem);
  margin: 0 0 2.5em;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.button {
  font: inherit;
  font-size: 1.05rem;
  min-width: 12rem;
  padding: 0.7rem 1.6rem;
  color: var(--ink);
  background: rgba(29, 36, 51, 0.55);
  border: 1px solid rgba(243, 234, 216, 0.35);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.button:hover,
.button:focus-visible {
  background: rgba(232, 162, 92, 0.25);
  border-color: var(--ember);
  outline: none;
  transform: translateY(-1px);
}

.button--quiet {
  min-width: 0;
  font-size: 0.9rem;
  padding: 0.4rem 1rem;
  border-color: transparent;
  background: transparent;
  color: var(--ink-dim);
}

.corner {
  position: absolute;
  z-index: 2;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
}

.text {
  font-family: var(--font-serif);
  font-size: clamp(1.05rem, 2.6vw, 1.3rem);
  line-height: 1.6;
  margin: 0 0 2em;
}

.mist {
  animation: drift 40s linear infinite alternate;
}

.mist--slow {
  animation-duration: 70s;
}

.ember-flicker {
  animation: flicker 3.2s ease-in-out infinite;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes drift {
  from { transform: translateX(-6%); }
  to { transform: translateX(6%); }
}

@keyframes flicker {
  0%, 100% { opacity: 0.85; }
  45% { opacity: 1; }
  60% { opacity: 0.7; }
}

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

/* --- Village ------------------------------------------------------------ */

.scene--world {
  background: linear-gradient(#121827 0 45%, #323549 55% 100%);
}

.scene--world .figure {
  cursor: pointer;
}

.is-talking .figure {
  cursor: default;
}

.scene--world .marker {
  opacity: 0;
  transition: opacity 0.4s;
  animation: bob 1.6s ease-in-out infinite;
}

.scene--world .figure.has-news .marker {
  opacity: 1;
}

.is-talking .marker {
  opacity: 0;
}

.scene--world .figure:hover .body {
  filter: brightness(1.15);
}

.bubble {
  animation: fade-in 0.25s ease both;
}

.bubble__shape {
  fill: #efe6d2;
}

.bubble--player .bubble__shape {
  fill: #f3d6a8;
}

.bubble__glyph {
  cursor: pointer;
}

.bubble__glyph:hover rect,
.bubble__glyph:focus-visible rect {
  fill: rgba(232, 162, 92, 0.25);
  outline: none;
}

.bubble__caption {
  font-family: var(--font-serif);
  font-size: 18px;
  fill: #6b5d4f;
}

.hud {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.notebook-button {
  min-width: 0;
}

.next {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  min-width: 9rem;
}

.next:hover,
.next:focus-visible {
  transform: translateX(-50%) translateY(-1px);
}

.next:disabled {
  opacity: 0.4;
  cursor: default;
}

.next[hidden] {
  display: none;
}

.toast {
  position: absolute;
  z-index: 3;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translate(-50%, -8px);
  width: min(32rem, calc(100% - 32px));
  margin: 0;
  padding: 0.8rem 1.2rem;
  border-radius: 14px;
  background: rgba(29, 36, 51, 0.85);
  border: 1px solid rgba(243, 234, 216, 0.2);
  font-family: var(--font-serif);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s, transform 0.4s;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.glyph {
  display: block;
  overflow: visible;
}

/* --- Overlays ----------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 12, 20, 0.6);
  animation: fade-in 0.25s ease both;
}

.overlay__panel {
  position: relative;
  width: min(56rem, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 1.5rem clamp(1rem, 3vw, 2.25rem) 2rem;
  border-radius: 18px;
  background: #efe6d2;
  color: #2a2236;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.overlay__panel h2 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.8rem;
  margin: 0 0 0.75rem;
}

.overlay__panel h3 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
}

.overlay__close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #6b5d4f;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.overlay__close:hover,
.overlay__close:focus-visible {
  background: rgba(107, 93, 79, 0.15);
  outline: none;
}

.muted {
  color: #6b5d4f;
  margin: 0 0 1rem;
}

.notebook__tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.5rem;
  margin-bottom: 1rem;
}

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

.notebook__script-name {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6b5d4f;
  margin-right: 0.2rem;
}

.tab {
  font: inherit;
  font-family: var(--font-serif);
  min-width: 3rem;
  padding: 0.35rem 0.9rem;
  border: 1px solid rgba(107, 93, 79, 0.35);
  border-radius: 999px;
  background: transparent;
  color: #2a2236;
  cursor: pointer;
}

.tab.is-active {
  background: #2a2236;
  border-color: #2a2236;
  color: #efe6d2;
}

.tab.is-known::after {
  content: ' ✓';
  color: #b5762f;
}

.tab.is-active.is-known::after {
  color: var(--ember);
}

.notebook__cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.8rem;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem;
  border-radius: 14px;
  border: 2px solid rgba(107, 93, 79, 0.2);
  background: #f7f1e3;
}

.card.is-selected {
  border-color: rgba(181, 118, 47, 0.6);
}

.card.is-known {
  border-color: #b5762f;
  background: #f9eedb;
}

.celebrate .card {
  animation: seal 0.7s ease both;
}

.card--unseen {
  justify-content: center;
  color: #9a8d7d;
  min-height: 9.5rem;
}

.card__unknown {
  font-family: var(--font-serif);
  font-size: 2.5rem;
}

.card__glyph {
  width: 5rem;
  height: 5rem;
  padding: 0.4rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #2a2236;
  cursor: pointer;
}

.card__glyph:hover,
.card__glyph:focus-visible {
  background: rgba(232, 162, 92, 0.2);
  outline: none;
}

.card__select {
  font: inherit;
  width: 100%;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(107, 93, 79, 0.4);
  background: #fffaf0;
  color: #2a2236;
}

.notebook__status {
  min-height: 1.5em;
  margin: 1rem 0;
  font-family: var(--font-serif);
  color: #6b5d4f;
}

.notebook__status[data-status='wrong'] {
  color: #a4553a;
}

.notebook__status.is-known {
  color: #8a5a22;
}

.notebook__seen {
  border-top: 1px solid rgba(107, 93, 79, 0.25);
  padding-top: 1rem;
}

.sentence {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
}

.sentence__word {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 3.2rem;
  padding: 0.2rem;
  border-radius: 8px;
}

.sentence__word .glyph {
  width: 2.6rem;
  height: 2.6rem;
}

.sentence__word small {
  font-family: var(--font-serif);
  color: #6b5d4f;
}

.sentence__word.is-highlight {
  background: rgba(232, 162, 92, 0.3);
}

/* --- Letter ------------------------------------------------------------- */

.writer__drawing {
  display: block;
  width: min(100%, 26rem);
  margin: 0 auto 1rem;
}

.writer__line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.slot {
  width: 3.4rem;
  height: 3.4rem;
  padding: 0.3rem;
  border-bottom: 2px solid rgba(107, 93, 79, 0.45);
}

.slot.is-filled {
  border-bottom-color: #2a2236;
}

.writer__keys {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.6rem, 1fr));
  gap: 0.4rem;
}

.key {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.35rem 0.2rem;
  border: 1px solid rgba(107, 93, 79, 0.3);
  border-radius: 10px;
  background: #f7f1e3;
  color: #2a2236;
  cursor: pointer;
}

.key .glyph {
  width: 2.4rem;
  height: 2.4rem;
}

.key small {
  font-family: var(--font-serif);
  color: #6b5d4f;
  min-height: 1.2em;
}

.key:hover,
.key:focus-visible {
  border-color: var(--ember);
  outline: none;
}

.writer__hints {
  margin: 0.5rem auto 0;
  padding: 0.6rem 1rem 0.6rem 2rem;
  max-width: 34rem;
  border-radius: 10px;
  background: rgba(232, 162, 92, 0.15);
  font-family: var(--font-serif);
  color: #5a4636;
}

.writer__hints li + li {
  margin-top: 0.3rem;
}

.writer .sentence {
  justify-content: center;
  margin: 0 0 1rem;
}

.writer__feedback {
  min-height: 1.5em;
  margin: 1rem 0 0;
  font-family: var(--font-serif);
  color: #a4553a;
  text-align: center;
}

.writer__actions {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.overlay .button {
  color: #2a2236;
  background: #f7f1e3;
  border-color: rgba(42, 34, 54, 0.4);
}

.overlay .button:hover,
.overlay .button:focus-visible {
  background: #f3dcbc;
  border-color: #b5762f;
}

.overlay .button--quiet {
  background: transparent;
  border-color: transparent;
}

.button:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

/* --- Ending ------------------------------------------------------------- */

.reply {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin: 0 0 1.5rem;
  color: var(--ink);
}

.reply .glyph {
  width: 3rem;
  height: 3rem;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes seal {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); box-shadow: 0 0 0 6px rgba(232, 162, 92, 0.35); }
  100% { transform: scale(1); }
}

.rotate-hint {
  display: none;
}

@media (max-width: 640px) {
  .next {
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 4rem);
  }
}

@media (orientation: portrait) and (max-width: 700px) {
  .rotate-hint {
    display: block;
    position: absolute;
    z-index: 1;
    left: 16px;
    right: 16px;
    top: 30%;
    margin: 0;
    text-align: center;
    font-family: var(--font-serif);
    color: var(--ink-dim);
  }
}
