:root {
  color-scheme: only light;
  --bg-top: #1d2738;
  --bg-bottom: #101720;
  --panel-outline: rgba(132, 81, 42, 0.18);
  --text-main: #2f1f1d;
  --text-soft: rgba(47, 31, 29, 0.72);
  --accent: #f08a4b;
  --accent-deep: #cb5f25;
  --sky: #79a6d2;
  --shadow: 0 26px 60px rgba(7, 14, 20, 0.32);
  --card-shadow: 0 18px 36px rgba(32, 19, 15, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --grid-line: rgba(60, 41, 34, 0.12);
  --good: #2f8b57;
  --warning: #ad5f19;
  --danger: #b34545;
  --paper: linear-gradient(145deg, rgba(255, 248, 239, 0.98), rgba(252, 240, 224, 0.92));
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--text-main);
  background:
    radial-gradient(circle at top left, rgba(240, 138, 75, 0.18), transparent 24%),
    radial-gradient(circle at top right, rgba(121, 166, 210, 0.16), transparent 22%),
    radial-gradient(circle at 20% 80%, rgba(140, 191, 166, 0.12), transparent 20%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background:
    radial-gradient(circle at 15% 25%, rgba(255, 244, 215, 0.08), transparent 9%),
    radial-gradient(circle at 70% 18%, rgba(255, 225, 186, 0.08), transparent 12%),
    radial-gradient(circle at 82% 74%, rgba(247, 208, 157, 0.05), transparent 10%);
}

body::after {
  background:
    linear-gradient(130deg, transparent 0 55%, rgba(255, 255, 255, 0.03) 60%, transparent 65%),
    linear-gradient(310deg, transparent 0 48%, rgba(255, 255, 255, 0.02) 53%, transparent 60%);
}

.app-shell {
  width: min(1280px, calc(100% - 24px));
  margin: 22px auto 32px;
}

.hero,
.panel,
.info-dialog {
  background: var(--paper);
  border: 1px solid var(--panel-outline);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(220px, 320px);
  gap: 20px;
  padding: 28px;
  border-radius: calc(var(--radius-xl) + 8px);
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  inset: auto -10% -45% auto;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(240, 138, 75, 0.23), transparent 65%);
}

.hero-copy h1,
.panel h2,
.panel h3,
.info-dialog h2 {
  font-family: "Palatino Linotype", "Book Antiqua", serif;
  letter-spacing: 0.01em;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.9rem);
  line-height: 0.95;
  max-width: 12ch;
}

.eyebrow,
.section-eyebrow,
.mini-label,
.stat-label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  color: var(--accent-deep);
}

.hero-text,
.muted-text,
.clue-body {
  color: var(--text-soft);
}

.hero-text {
  max-width: 56ch;
  font-size: 1.02rem;
  margin: 16px 0 0;
}

.hero-actions,
.action-stack,
.tool-tray,
.swatch-group,
.settings-grid,
.mode-toggle,
.banner-meta,
.dialog-header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  font: inherit;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease, opacity 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:focus-visible {
  outline: 3px solid rgba(121, 166, 210, 0.55);
  outline-offset: 2px;
}

.primary-button,
.secondary-button,
.ghost-button,
.tab-button,
.tool-button,
.chapter-chip,
.swatch-button,
.setting-button {
  padding: 11px 16px;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: white;
  box-shadow: 0 12px 28px rgba(203, 95, 37, 0.28);
}

.secondary-button,
.tab-button,
.chapter-chip,
.setting-button {
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-main);
  border: 1px solid rgba(132, 81, 42, 0.14);
}

.ghost-button,
.tool-button,
.swatch-button {
  background: rgba(244, 230, 214, 0.65);
  color: var(--text-main);
  border: 1px solid rgba(132, 81, 42, 0.12);
}

.tab-button.is-active,
.tool-button.is-active,
.chapter-chip.is-active,
.swatch-button.is-active,
.setting-button.is-active {
  background: linear-gradient(135deg, rgba(240, 138, 75, 0.18), rgba(255, 221, 186, 0.9));
  color: var(--accent-deep);
  border-color: rgba(203, 95, 37, 0.2);
}

.hero-stats {
  display: grid;
  gap: 14px;
  align-content: start;
}

.stat-card {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(132, 81, 42, 0.12);
  padding: 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.15rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.9fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.main-column,
.side-column {
  display: grid;
  gap: 18px;
}

.panel {
  border-radius: var(--radius-xl);
  padding: 20px;
}

.panel-heading,
.puzzle-banner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.panel h2,
.panel h3,
.puzzle-banner h2 {
  margin: 4px 0 0;
}

.badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(132, 81, 42, 0.12);
  color: var(--text-main);
  white-space: nowrap;
}

.badge-highlight,
.status-pill.is-good {
  background: rgba(240, 138, 75, 0.18);
  color: var(--accent-deep);
}

.status-pill.is-warning {
  background: rgba(173, 95, 25, 0.14);
  color: var(--warning);
}

.status-pill.is-danger {
  background: rgba(179, 69, 69, 0.14);
  color: var(--danger);
}

.chapter-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.chapter-chip.is-locked {
  opacity: 0.42;
}

.building-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.apartment-card {
  position: relative;
  min-height: 200px;
  border-radius: 26px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255, 253, 249, 0.95), rgba(252, 240, 226, 0.92)),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 32px,
      rgba(121, 166, 210, 0.05) 32px,
      rgba(121, 166, 210, 0.05) 33px
    );
  border: 1px solid rgba(132, 81, 42, 0.12);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.apartment-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(255, 226, 174, 0.32), transparent 25%),
    radial-gradient(circle at bottom right, rgba(121, 166, 210, 0.14), transparent 22%);
  pointer-events: none;
}

.apartment-card.is-solved {
  animation: glowPulse 1800ms ease-in-out infinite;
}

.apartment-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.apartment-number {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(132, 81, 42, 0.12);
  font-weight: 700;
}

.apartment-meta {
  color: var(--text-soft);
  font-size: 0.9rem;
}

.occupant-panel {
  position: relative;
  margin-top: 18px;
  display: grid;
  gap: 12px;
}

.ghost-token,
.letter-token,
.empty-token {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(132, 81, 42, 0.12);
}

.ghost-bubble,
.letter-bubble {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.84rem;
  color: white;
}

.ghost-bubble {
  background: linear-gradient(135deg, var(--sky), #567ab7);
}

.letter-bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
}

.empty-token {
  color: var(--text-soft);
  border-style: dashed;
}

.mail-run {
  position: absolute;
  inset: auto 14px 14px auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(255, 214, 171, 0.94), rgba(240, 138, 75, 0.94));
  color: white;
  transform: scale(0.92);
  opacity: 0;
}

.mail-run.is-playing {
  animation: satchelHop 1500ms ease-in-out 1;
}

.clue-cards {
  display: grid;
  gap: 12px;
}

.clue-card {
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(132, 81, 42, 0.12);
  border-radius: 20px;
  padding: 14px 16px;
  box-shadow: var(--card-shadow);
  position: relative;
  overflow: hidden;
}

.clue-card::after {
  content: "";
  position: absolute;
  inset: auto -30px -30px auto;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(240, 138, 75, 0.12), transparent 70%);
  pointer-events: none;
}

.clue-card[data-tone="lie"] {
  border-style: dashed;
  background: linear-gradient(135deg, rgba(255, 239, 230, 0.94), rgba(255, 246, 237, 0.82));
}

.clue-card[data-tone="hidden"] {
  background: linear-gradient(135deg, rgba(33, 42, 59, 0.96), rgba(18, 26, 36, 0.94));
  color: rgba(255, 245, 225, 0.92);
  border-color: rgba(255, 222, 186, 0.18);
}

.clue-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
}

.clue-type {
  color: var(--accent-deep);
  font-weight: 700;
}

.clue-card[data-tone="hidden"] .clue-type {
  color: rgba(255, 210, 164, 0.9);
}

.matrix-area {
  display: grid;
  gap: 18px;
}

.matrix-card {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(132, 81, 42, 0.12);
  border-radius: 20px;
  padding: 16px;
}

.matrix-card h4 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.matrix-grid {
  display: grid;
  grid-template-columns: 152px repeat(4, minmax(54px, 1fr));
  gap: 6px;
  align-items: center;
}

.matrix-corner,
.matrix-header,
.matrix-row-label {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(248, 238, 224, 0.8);
  border: 1px solid rgba(132, 81, 42, 0.09);
  font-size: 0.92rem;
}

.matrix-row-label {
  justify-content: flex-start;
  padding: 10px 12px;
}

.matrix-cell {
  position: relative;
  min-height: 54px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--grid-line);
  display: grid;
  place-items: center;
  font-weight: 700;
  box-shadow: 0 6px 10px rgba(40, 24, 18, 0.04);
}

.matrix-cell::after {
  content: attr(data-mark);
  font-size: 1.08rem;
}

.matrix-cell[data-state="maybe"] {
  background: rgba(121, 166, 210, 0.16);
  color: #456487;
}

.matrix-cell[data-state="no"] {
  background: rgba(179, 69, 69, 0.12);
  color: var(--danger);
}

.matrix-cell[data-state="locked"] {
  background: linear-gradient(135deg, rgba(240, 138, 75, 0.3), rgba(255, 226, 174, 0.85));
  color: var(--accent-deep);
  border-color: rgba(203, 95, 37, 0.3);
}

.matrix-cell[data-state="blocked"] {
  background: rgba(240, 236, 230, 0.68);
  color: rgba(74, 55, 48, 0.42);
}

.matrix-cell[data-state="solution"] {
  background: linear-gradient(135deg, rgba(86, 171, 122, 0.26), rgba(214, 245, 225, 0.94));
  color: var(--good);
  border-color: rgba(47, 139, 87, 0.24);
}

.action-stack {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.status-grid div {
  background: rgba(255, 255, 255, 0.68);
  border-radius: 18px;
  padding: 14px;
  border: 1px solid rgba(132, 81, 42, 0.1);
}

.solve-ribbon {
  margin: 14px 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-radius: 18px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(255, 243, 220, 0.98), rgba(255, 229, 179, 0.92));
  border: 1px solid rgba(203, 95, 37, 0.14);
}

.swatch-button {
  min-width: 136px;
  justify-content: center;
}

.swatch-button::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--swatch);
  display: inline-block;
  margin-right: 10px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
}

.setting-button {
  min-width: 140px;
  justify-content: center;
}

.info-dialog {
  width: min(540px, calc(100% - 24px));
  border: 1px solid rgba(132, 81, 42, 0.14);
  border-radius: 24px;
  padding: 22px;
}

.dialog-list {
  display: grid;
  gap: 10px;
  padding-left: 20px;
}

.toast {
  position: fixed;
  inset: auto 16px 16px auto;
  max-width: min(360px, calc(100% - 32px));
  padding: 14px 16px;
  border-radius: 18px;
  color: white;
  background: rgba(16, 23, 32, 0.92);
  box-shadow: var(--shadow);
  z-index: 10;
}

.toast.is-visible {
  animation: toastSlide 240ms ease forwards;
}

.app-shell.reduced-motion *,
.app-shell.reduced-motion *::before,
.app-shell.reduced-motion *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 1ms !important;
  scroll-behavior: auto !important;
}

@keyframes satchelHop {
  0% {
    opacity: 0;
    transform: translate(0, 8px) scale(0.88);
  }
  18% {
    opacity: 1;
    transform: translate(-16px, -20px) rotate(-8deg);
  }
  42% {
    opacity: 1;
    transform: translate(-100px, -86px) rotate(8deg);
  }
  70% {
    opacity: 1;
    transform: translate(-8px, -128px) rotate(-6deg);
  }
  100% {
    opacity: 0;
    transform: translate(-120px, -186px) scale(0.88);
  }
}

@keyframes glowPulse {
  0%,
  100% {
    box-shadow: var(--card-shadow);
  }
  50% {
    box-shadow: 0 22px 44px rgba(240, 138, 75, 0.2);
  }
}

@keyframes toastSlide {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1100px) {
  .layout,
  .hero {
    grid-template-columns: 1fr;
  }

  .status-grid,
  .action-stack {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100%, calc(100% - 12px));
    margin: 10px auto 24px;
  }

  .hero,
  .panel {
    padding: 16px;
    border-radius: 22px;
  }

  .building-grid {
    grid-template-columns: 1fr;
  }

  .matrix-grid {
    grid-template-columns: 112px repeat(4, minmax(46px, 1fr));
    gap: 4px;
  }

  .matrix-header,
  .matrix-row-label,
  .matrix-cell,
  .matrix-corner {
    min-height: 44px;
    font-size: 0.82rem;
  }

  .hero-copy h1 {
    max-width: none;
  }
}
