:root {
  --bg: #09080b;
  --bg-panel: #131015;
  --bg-card: #19151b;
  --gold: #cfa660;
  --gold-dim: #8a6c39;
  --crimson: #8f232c;
  --crimson-bright: #c43b46;
  --text: #e6dcc8;
  --text-dim: #a99b84;
  --border: #3a2e22;
  --ok: #78b377;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 15%, #1d1518 0%, #09080b 70%);
  color: var(--text);
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", Palatino, serif;
  font-size: 16px;
  line-height: 1.6;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 14px 52px;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.85);
  z-index: 10;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 35%, #1e1418 0%, #070609 75%);
  transition: opacity 0.45s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-card {
  width: 100%;
  max-width: 520px;
  border: 1px solid var(--gold-dim);
  outline: 4px solid rgba(19, 16, 21, 0.9);
  background: linear-gradient(180deg, rgba(24, 19, 26, 0.98) 0%, rgba(12, 10, 14, 0.99) 100%);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.9), 0 0 50px rgba(207, 166, 96, 0.08);
  padding: 36px 28px;
  text-align: center;
}

.loading-sigil {
  color: var(--gold);
  margin-bottom: 14px;
  animation: sigilPulse 2.4s ease-in-out infinite;
}

@keyframes sigilPulse {
  0%, 100% {
    opacity: 0.72;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.06);
  }
}

.loading-eyebrow {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.76rem;
  letter-spacing: 0.2em;
  color: var(--gold-dim);
  margin-bottom: 6px;
}

.loading-title {
  margin: 0 0 10px;
  font-size: 1.85rem;
  font-weight: normal;
  letter-spacing: 0.12em;
  color: var(--gold);
}

.loading-subtitle {
  margin: 0 0 22px;
  color: var(--text-dim);
  font-size: 0.98rem;
  font-style: italic;
}

.loading-bar-track {
  width: 100%;
  height: 8px;
  border: 1px solid var(--gold-dim);
  background: #0a080c;
  margin-bottom: 12px;
  overflow: hidden;
}

.loading-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--crimson) 0%, var(--gold) 100%);
  transition: width 0.35s ease;
}

.loading-status {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  min-height: 22px;
}

.loading-start-btn {
  margin-top: 20px;
  padding: 11px 24px;
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.dossier-shell {
  width: 100%;
  max-width: 900px;
  background: linear-gradient(180deg, rgba(22, 18, 24, 0.96) 0%, rgba(14, 12, 16, 0.98) 100%);
  border: 1px solid var(--gold-dim);
  outline: 4px solid rgba(19, 16, 21, 0.8);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(207, 166, 96, 0.06);
  padding: 26px 30px;
  position: relative;
}

.dossier-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.header-sigil {
  color: var(--gold);
  display: flex;
}

.header-meta {
  flex: 1;
  min-width: 210px;
}

.header-eyebrow {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  color: var(--gold-dim);
}

.header-title {
  margin: 2px 0 0;
  font-size: 1.5rem;
  font-weight: normal;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.progress-pips {
  display: flex;
  gap: 6px;
  margin-right: 6px;
}

.pip {
  width: 11px;
  height: 11px;
  border: 1px solid var(--gold-dim);
  transform: rotate(45deg);
  transition: all 0.25s ease;
}

.pip.done {
  background: var(--gold);
  border-color: var(--gold);
}

.pip.active {
  background: var(--crimson);
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(196, 59, 70, 0.65);
}

.ornate-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--gold-dim);
  font-family: Georgia, serif;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  padding: 7px 14px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.ornate-btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(207, 166, 96, 0.08);
}

.ornate-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ornate-btn-primary {
  background: linear-gradient(180deg, #741c24 0%, #521218 100%);
  border-color: var(--gold-dim);
  color: var(--text);
}

.ornate-btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #8f232c 0%, #66171f 100%);
  border-color: var(--gold);
  color: #fff5e1;
}

.ornate-btn-subtle {
  font-size: 0.82rem;
  padding: 5px 11px;
}

.ornate-btn-dim {
  font-size: 0.82rem;
  padding: 5px 11px;
  color: var(--text-dim);
  border-color: var(--border);
}

.narrator-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  background: rgba(11, 9, 13, 0.72);
}

.narrator-bar.attention #btn-narrator {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 12px rgba(207, 166, 96, 0.28);
}

.narrator-status {
  flex: 1;
  font-size: 0.86rem;
  font-style: italic;
  color: var(--text-dim);
  min-width: 180px;
}

.act-banner {
  margin-bottom: 18px;
}

.act-title {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  color: var(--gold);
  margin-bottom: 6px;
}

.act-desc {
  margin: 0;
  color: var(--text);
  font-size: 1rem;
}

.feedback-box {
  padding: 10px 14px;
  margin-bottom: 16px;
  border-left: 3px solid var(--gold);
  background: rgba(207, 166, 96, 0.07);
  font-size: 0.95rem;
}

.feedback-box.err {
  border-left-color: var(--crimson-bright);
  background: rgba(143, 35, 44, 0.18);
  color: #f3c4c7;
}

.feedback-box.ok {
  border-left-color: var(--ok);
  background: rgba(120, 179, 119, 0.1);
  color: #d6eed6;
}

.feedback-box.hint {
  border-left-color: var(--gold);
  color: #f0dfb9;
  font-style: italic;
}

.stage-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.badge-info {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.86rem;
  color: var(--gold);
  border: 1px solid var(--border);
  background: #0d0b0f;
  padding: 6px 12px;
}

/* --- AKT I: PIANINO --- */
.piano-wrap {
  position: relative;
  width: 100%;
  max-width: 560px;
  height: 200px;
  user-select: none;
  border: 2px solid var(--gold-dim);
  background: #0b090d;
  padding: 8px;
}

.piano-whites {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  height: 100%;
}

.key-white {
  background: linear-gradient(180deg, #dcd2be 0%, #bfb195 100%);
  border: 1px solid #3c3224;
  border-radius: 0 0 4px 4px;
  color: #2b2217;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.78rem;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.1s ease, background 0.1s ease;
}

.key-white.lit,
.key-white:active {
  background: linear-gradient(180deg, #ffe39e 0%, #cfa660 100%);
  box-shadow: 0 0 18px rgba(207, 166, 96, 0.8);
  transform: translateY(2px);
}

.key-black {
  position: absolute;
  top: 8px;
  width: 8.4%;
  height: 58%;
  background: linear-gradient(180deg, #252028 0%, #09080b 100%);
  border: 1px solid var(--gold-dim);
  border-radius: 0 0 4px 4px;
  color: var(--gold);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.68rem;
  cursor: pointer;
  z-index: 2;
  transition: transform 0.06s ease, box-shadow 0.1s ease, background 0.1s ease;
}

.key-black.lit,
.key-black:active {
  background: linear-gradient(180deg, #b52e37 0%, #6d151c 100%);
  box-shadow: 0 0 18px rgba(196, 59, 70, 0.9);
  transform: translateY(2px);
}

.melody-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  min-height: 20px;
}

.melody-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--gold-dim);
}

.melody-dot.filled {
  background: var(--gold);
  box-shadow: 0 0 8px rgba(207, 166, 96, 0.7);
}

/* --- AKT II: SUDOKU --- */
.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  max-width: 432px;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--gold);
  background: #0d0b0f;
}

.sudoku-cell {
  border: 1px solid #2b231d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Courier New", Courier, monospace;
  font-size: 1.25rem;
  cursor: pointer;
  user-select: none;
  background: #141117;
  color: var(--text);
  transition: background-color 0.12s ease;
}

.sudoku-cell.given {
  color: var(--gold);
  font-weight: bold;
  background: #1b161c;
  cursor: default;
}

.sudoku-cell.selected {
  background: rgba(143, 35, 44, 0.38);
  outline: 1px solid var(--gold);
  z-index: 1;
}

.sudoku-cell.box-right {
  border-right: 2px solid var(--gold-dim);
}

.sudoku-cell.box-bottom {
  border-bottom: 2px solid var(--gold-dim);
}

.numpad {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.numpad-btn {
  min-width: 38px;
  padding: 7px 10px;
  font-family: "Courier New", Courier, monospace;
  font-size: 1rem;
}

/* --- AKT III: SAPER --- */
.mines-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 420px;
  padding: 8px;
  border: 2px solid var(--gold-dim);
  background: #0c0a0d;
}

.mine-cell {
  aspect-ratio: 1 / 1;
  background: linear-gradient(180deg, #272129 0%, #19151b 100%);
  border: 1px solid #493a2b;
  color: var(--text);
  font-family: "Courier New", Courier, monospace;
  font-size: 1rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  user-select: none;
}

.mine-cell:hover:not(.revealed) {
  border-color: var(--gold);
}

.mine-cell.revealed {
  background: #0e0c10;
  border-color: #241d18;
  cursor: default;
}

.mine-cell.flagged {
  color: var(--crimson-bright);
  border-color: var(--crimson);
}

.mine-cell.boom {
  background: #5c1218;
  border-color: var(--crimson-bright);
  color: #ffd7c2;
}

.adj-1 { color: #7cb8ff; }
.adj-2 { color: #78b377; }
.adj-3 { color: #e26d5c; }
.adj-4 { color: #cfa660; }
.adj-5 { color: #d376c6; }
.adj-6 { color: #5ec4b6; }
.adj-7 { color: #f0dfb9; }
.adj-8 { color: #a99b84; }

/* --- AKT IV: LABIRYNT --- */
.maze-canvas {
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--gold-dim);
  background: #050406;
  image-rendering: pixelated;
  cursor: pointer;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 42px);
  gap: 6px;
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }

/* --- AKT V: PUZZLE 4x4 --- */
.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1 / 1;
  padding: 6px;
  border: 2px solid var(--gold-dim);
  background: #0a080b;
}

.puzzle-tile {
  position: relative;
  border: 1px solid #4a3b2a;
  background-color: #141016;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.puzzle-tile:hover {
  border-color: var(--gold);
}

.puzzle-tile.empty {
  background: #070608;
  border: 1px dashed #2e241b;
  cursor: default;
}

.puzzle-tile canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* --- AKT VI: FINAŁ --- */
.final-screen {
  padding: 12px 4px 8px;
}

.wax-seal {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #b52e37, #68141b);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 18px;
  box-shadow: 0 4px 16px rgba(143, 35, 44, 0.5);
}

.final-typewriter {
  display: inline;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 1.08rem;
  line-height: 1.75;
}

.cursor {
  display: inline-block;
  color: var(--gold);
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.final-actions {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.key-plaque {
  font-family: "Courier New", Courier, monospace;
  font-size: 1.2rem;
  letter-spacing: 0.16em;
  color: var(--gold);
  border: 1px dashed var(--gold-dim);
  background: #0b090d;
  padding: 10px 18px;
}

.copy-feedback {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-style: italic;
}

.hidden {
  display: none !important;
}

@media (max-width: 600px) {
  .dossier-shell {
    padding: 18px 14px;
  }
  .piano-wrap {
    height: 165px;
  }
  .sudoku-cell {
    font-size: 1rem;
  }
}
