:root {
  color-scheme: dark;
  --bg: #0d0907;
  --bg-soft: #17100c;
  --panel: rgba(26, 18, 13, 0.94);
  --panel-light: rgba(42, 29, 20, 0.94);
  --border: rgba(232, 169, 85, 0.28);
  --border-strong: rgba(255, 190, 94, 0.55);
  --text: #f6ead6;
  --muted: #b9a48a;
  --gold: #ffc05e;
  --gold-bright: #ffe0a0;
  --ember: #f06b2b;
  --ember-dark: #8c2d14;
  --success: #8fe0a4;
  --danger: #ff8f7d;
  --stone: #33271f;
  --stone-light: #4b392d;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 18%, rgba(122, 51, 17, 0.25), transparent 34rem),
    linear-gradient(180deg, #160e09 0%, #0d0907 48%, #080605 100%);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.embers,
.background-runes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.embers {
  opacity: 0.32;
  background-image:
    radial-gradient(circle, rgba(255, 166, 79, 0.9) 0 1px, transparent 1.6px),
    radial-gradient(circle, rgba(255, 94, 32, 0.75) 0 1px, transparent 1.8px);
  background-size: 83px 83px, 137px 137px;
  background-position: 0 0, 36px 51px;
  animation: emberDrift 26s linear infinite;
  mask-image: linear-gradient(to top, black, transparent 80%);
}

.background-runes {
  opacity: 0.12;
  background:
    linear-gradient(30deg, transparent 48%, rgba(255, 194, 99, 0.24) 49%, transparent 51%) 0 0 / 92px 92px,
    linear-gradient(-30deg, transparent 48%, rgba(255, 194, 99, 0.18) 49%, transparent 51%) 0 0 / 92px 92px;
}

@keyframes emberDrift {
  from { transform: translateY(0); }
  to { transform: translateY(-83px); }
}

.topbar {
  width: min(1180px, calc(100% - 28px));
  min-height: 86px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.12em;
  text-align: center;
}

.brand-main {
  color: var(--gold-bright);
  font-size: clamp(1.35rem, 3vw, 2rem);
  font-weight: 900;
  text-shadow: 0 0 22px rgba(255, 166, 65, 0.34);
}

.brand-sub {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.25em;
}

.icon-button,
.close-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.icon-button {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 2px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
}

.icon-button:last-child {
  justify-self: end;
}

.icon-button:hover {
  color: var(--gold-bright);
}

.game-shell {
  width: min(1120px, calc(100% - 28px));
  margin: 24px auto 56px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--border);
  box-shadow: var(--shadow);
}

.status-strip > div {
  padding: 12px 16px;
  background: rgba(20, 14, 10, 0.88);
}

.status-label {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.status-strip strong {
  color: var(--gold-bright);
  font-size: 1rem;
}

.forge {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background:
    linear-gradient(160deg, rgba(49, 31, 20, 0.72), rgba(16, 11, 8, 0.95) 42%),
    var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.forge-heading {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 24px clamp(18px, 5vw, 64px);
  border-bottom: 1px solid var(--border);
  background: rgba(10, 7, 5, 0.28);
}

.word-goal {
  text-align: center;
}

.goal-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.word-goal strong {
  font-family: Georgia, serif;
  font-size: clamp(1.5rem, 4vw, 2.55rem);
  letter-spacing: 0.14em;
}

.word-goal.target strong {
  color: var(--gold-bright);
  text-shadow: 0 0 20px rgba(255, 182, 79, 0.25);
}

.goal-arrow {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 20px;
}

.goal-arrow span {
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  border: 1px solid var(--border-strong);
}

.goal-arrow span:nth-child(2) {
  background: var(--gold);
  box-shadow: 0 0 16px rgba(255, 171, 55, 0.58);
}

.forge-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(330px, 0.9fr);
  min-height: 520px;
}

.chain-panel {
  position: relative;
  padding: 24px;
  border-right: 1px solid var(--border);
  background:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px) 0 0 / 100% 42px,
    rgba(12, 8, 6, 0.34);
}

.chain-panel::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 72px;
  bottom: 32px;
  width: 2px;
  background: linear-gradient(var(--gold), rgba(255, 165, 54, 0.06));
  box-shadow: 0 0 18px rgba(255, 143, 34, 0.2);
}

.chain-header {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.chain-list {
  position: relative;
  z-index: 1;
  list-style: none;
  padding: 20px 0 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chain-word {
  width: min(360px, 82%);
  margin-inline: auto;
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  align-items: center;
  min-height: 54px;
  padding: 7px 12px;
  border: 1px solid rgba(224, 183, 127, 0.24);
  border-radius: 6px;
  background:
    linear-gradient(115deg, rgba(255,255,255,0.05), transparent 28%),
    linear-gradient(180deg, var(--stone-light), var(--stone));
  box-shadow: 0 7px 16px rgba(0,0,0,0.28), inset 0 1px rgba(255,255,255,0.06);
  font-family: Georgia, serif;
  font-size: clamp(1.05rem, 3vw, 1.45rem);
  letter-spacing: 0.22em;
  text-align: center;
  text-transform: uppercase;
}

.chain-word::before,
.chain-word::after {
  content: "◆";
  color: rgba(255, 202, 127, 0.28);
  font-family: inherit;
  font-size: 0.55rem;
}

.chain-word.current {
  border-color: var(--border-strong);
  background:
    linear-gradient(115deg, rgba(255,255,255,0.08), transparent 28%),
    linear-gradient(180deg, #5c3a25, #392219);
  box-shadow: 0 0 24px rgba(241, 100, 36, 0.2), inset 0 1px rgba(255,255,255,0.08);
}

.changed-letter {
  color: var(--gold-bright);
  text-shadow: 0 0 10px rgba(255, 149, 49, 0.74);
}

.anvil-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 24px;
  background:
    radial-gradient(circle at 50% 54%, rgba(234, 79, 23, 0.16), transparent 19rem),
    rgba(26, 17, 12, 0.38);
}

.anvil-top {
  width: min(390px, 90%);
  height: 26px;
  border: 1px solid rgba(237, 187, 121, 0.3);
  border-radius: 9px 9px 3px 3px;
  background: linear-gradient(180deg, #55443a, #27201c);
  clip-path: polygon(0 28%, 20% 28%, 26% 0, 74% 0, 80% 28%, 100% 28%, 100% 100%, 0 100%);
}

.anvil-body {
  width: min(410px, 100%);
  padding: 28px clamp(18px, 4vw, 34px) 32px;
  border-inline: 1px solid rgba(237, 187, 121, 0.18);
  background: linear-gradient(180deg, rgba(44, 34, 28, 0.92), rgba(21, 16, 13, 0.96));
  text-align: center;
}

.anvil-base {
  width: min(330px, 76%);
  height: 28px;
  border: 1px solid rgba(237, 187, 121, 0.22);
  background: linear-gradient(180deg, #302721, #18120f);
  clip-path: polygon(14% 0, 86% 0, 100% 100%, 0 100%);
}

.current-instruction {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.word-input-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.word-input {
  width: 100%;
  height: 64px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--gold-bright);
  background: #0c0907;
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.62), 0 0 22px rgba(245, 111, 30, 0.08);
  font-family: Georgia, serif;
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
  text-transform: uppercase;
}

.primary-button,
.secondary-button {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(1px);
}

.primary-button {
  width: 100%;
  margin-top: 14px;
  padding: 14px 18px;
  color: #261307;
  background: linear-gradient(180deg, #ffd47d, #e98a31);
  border-color: #ffd28b;
  font-weight: 900;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  box-shadow: 0 8px 18px rgba(119, 45, 10, 0.32);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.hammer {
  display: inline-block;
  margin-right: 8px;
}

.secondary-actions,
.completion-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.secondary-button {
  padding: 11px 12px;
  color: var(--text);
  background: rgba(255,255,255,0.035);
  border-color: var(--border);
}

.secondary-button:hover {
  border-color: var(--border-strong);
  background: rgba(255, 191, 96, 0.07);
}

.feedback,
.hint-text {
  min-height: 1.4em;
  margin: 14px 0 0;
  font-size: 0.9rem;
}

.feedback {
  color: var(--muted);
}

.feedback.success {
  color: var(--success);
}

.feedback.error {
  color: var(--danger);
}

.hint-text {
  color: var(--gold-bright);
}

.progress-panel {
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(20, 14, 10, 0.9);
  box-shadow: var(--shadow);
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.83rem;
}

.progress-copy strong {
  color: var(--text);
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #080605;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.8);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--ember-dark), var(--gold));
  box-shadow: 0 0 13px rgba(255, 151, 52, 0.42);
  transition: width 220ms ease;
}

.star-guide {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 18px;
  margin-top: 11px;
  color: var(--muted);
  font-size: 0.72rem;
}

.modal {
  width: min(760px, calc(100% - 24px));
  max-height: min(82vh, 820px);
  padding: 0;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background:
    linear-gradient(145deg, rgba(55, 35, 23, 0.98), rgba(15, 10, 7, 0.99) 52%);
  box-shadow: 0 30px 80px rgba(0,0,0,0.68);
}

.modal::backdrop {
  background: rgba(4, 3, 2, 0.78);
  backdrop-filter: blur(5px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
}

.modal h2 {
  margin: 2px 0 0;
  font-family: Georgia, serif;
}

.eyebrow {
  color: var(--gold);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.close-button {
  width: 42px;
  height: 42px;
  color: var(--muted);
  font-size: 1.8rem;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 22px;
  overflow-y: auto;
}

.level-card {
  min-height: 84px;
  padding: 10px 7px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  background: rgba(255,255,255,0.025);
  cursor: pointer;
}

.level-card:hover:not(:disabled),
.level-card.current {
  border-color: var(--gold);
  background: rgba(255, 181, 70, 0.08);
}

.level-card:disabled {
  cursor: not-allowed;
  opacity: 0.34;
}

.level-card strong,
.level-card span {
  display: block;
}

.level-card strong {
  font-size: 1.05rem;
}

.level-card .level-tier {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.level-card .level-stars {
  min-height: 1.2em;
  margin-top: 7px;
  color: var(--gold-bright);
  letter-spacing: 0.06em;
}

.help-content {
  padding: 24px;
}

.rule-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: start;
  gap: 14px;
  margin-bottom: 16px;
}

.rule-row > span {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-strong);
  transform: rotate(45deg);
  color: var(--gold-bright);
}

.rule-row > span::first-line {
  transform: rotate(-45deg);
}

.rule-row p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.complete-modal {
  width: min(480px, calc(100% - 24px));
  padding: 34px 28px 28px;
  text-align: center;
}

.completion-mark {
  width: 66px;
  height: 66px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  transform: rotate(45deg);
  color: var(--gold-bright);
  background: rgba(255, 168, 54, 0.08);
  box-shadow: 0 0 30px rgba(255, 124, 31, 0.18);
}

.complete-modal h2 {
  margin: 8px 0 4px;
}

.earned-stars {
  margin: 12px 0;
  color: var(--gold-bright);
  font-size: 2.2rem;
  letter-spacing: 0.12em;
  text-shadow: 0 0 18px rgba(255, 150, 45, 0.36);
}

.complete-modal p {
  color: var(--muted);
  line-height: 1.5;
}

.complete-modal .primary-button {
  margin-top: 0;
}

body.shake .anvil-body {
  animation: shake 240ms linear;
}

body.strike .anvil-body {
  animation: strike 260ms ease;
}

@keyframes shake {
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

@keyframes strike {
  0% { filter: brightness(1); }
  35% { filter: brightness(1.7); box-shadow: 0 0 34px rgba(255, 137, 44, 0.34); }
  100% { filter: brightness(1); }
}

@media (max-width: 820px) {
  .forge-grid {
    grid-template-columns: 1fr;
  }

  .chain-panel {
    min-height: 320px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .anvil-panel {
    padding-block: 24px 34px;
  }
}

@media (max-width: 620px) {
  .topbar {
    min-height: 74px;
  }

  .brand {
    display: block;
  }

  .brand-sub {
    display: block;
    margin-top: 3px;
  }

  .icon-button span:last-child {
    display: none;
  }

  .status-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .forge-heading {
    padding: 20px 10px;
  }

  .goal-arrow {
    padding: 0 8px;
    gap: 4px;
  }

  .goal-arrow span {
    width: 5px;
    height: 5px;
  }

  .chain-panel {
    padding: 20px 14px;
  }

  .chain-word {
    width: 92%;
  }

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

  .star-guide {
    display: grid;
  }
}

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

/* Mobiilin tiivistetty pelitila */
.mobile-play-summary {
  display: none;
}

.mobile-keyboard-close {
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

@media (max-width: 820px) {
  .forge-grid {
    grid-template-areas:
      "anvil"
      "chain";
  }

  .anvil-panel {
    grid-area: anvil;
  }

  .chain-panel {
    grid-area: chain;
  }

  .mobile-play-summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: rgba(10, 7, 5, 0.72);
    text-align: left;
  }

  .mobile-word-route {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
  }

  .mobile-route-word {
    min-width: 0;
  }

  .mobile-route-word small {
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 0.58rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .mobile-route-word strong {
    display: block;
    overflow: hidden;
    color: var(--text);
    font-family: Georgia, serif;
    font-size: 1.08rem;
    letter-spacing: 0.1em;
    text-overflow: ellipsis;
  }

  .mobile-route-word.target strong {
    color: var(--gold-bright);
  }

  .mobile-route-arrow {
    color: var(--ember);
  }

  .mobile-summary-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.68rem;
    white-space: nowrap;
  }

  .mobile-summary-meta strong {
    color: var(--gold-bright);
  }

  .mobile-keyboard-close {
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 1.2rem;
    line-height: 1;
  }
}

@media (max-width: 620px) {
  .game-shell {
    width: min(100% - 16px, 1120px);
    margin-top: 10px;
    margin-bottom: 24px;
  }

  .forge {
    margin-top: 10px;
    border-radius: 12px;
  }

  .forge-heading {
    padding-block: 12px;
  }

  .word-goal strong {
    font-size: 1.25rem;
  }

  .anvil-panel {
    padding: 12px 10px 14px;
  }

  .anvil-top,
  .anvil-base {
    display: none;
  }

  .anvil-body {
    width: 100%;
    padding: 14px;
    border: 1px solid rgba(237, 187, 121, 0.18);
    border-radius: 10px;
  }

  .current-instruction {
    margin-bottom: 12px;
    font-size: 0.88rem;
  }

  .word-input {
    height: 54px;
    font-size: 1.5rem;
  }

  .primary-button {
    margin-top: 9px;
    padding-block: 11px;
  }

  .secondary-actions {
    margin-top: 7px;
  }

  .secondary-button {
    padding-block: 9px;
  }

  .feedback,
  .hint-text {
    min-height: 1.1em;
    margin-top: 8px;
    font-size: 0.8rem;
  }

  .chain-panel {
    min-height: 0;
    padding: 14px 10px 16px;
  }

  .chain-panel::before {
    display: none;
  }

  .chain-list {
    padding-top: 12px;
    gap: 7px;
  }

  .chain-word {
    width: 100%;
    min-height: 42px;
    padding-block: 5px;
    font-size: 1rem;
  }

  .chain-word:not(:nth-last-child(-n + 4)) {
    display: none;
  }

  .progress-panel {
    margin-top: 10px;
    padding: 13px 14px;
  }
}

@media (max-width: 820px) {
  body.mobile-input-mode {
    overflow: hidden;
  }

  body.mobile-input-mode .topbar,
  body.mobile-input-mode .status-strip,
  body.mobile-input-mode .forge-heading,
  body.mobile-input-mode .chain-panel,
  body.mobile-input-mode .progress-panel {
    display: none;
  }

  body.mobile-input-mode .game-shell {
    width: 100%;
    margin: 0;
  }

  body.mobile-input-mode .forge {
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body.mobile-input-mode .forge-grid {
    min-height: 0;
  }

  body.mobile-input-mode .anvil-panel {
    min-height: 0;
    justify-content: flex-start;
    padding: max(6px, env(safe-area-inset-top)) 8px 8px;
    background: var(--bg-soft);
  }

  body.mobile-input-mode .anvil-body {
    width: 100%;
    padding: 8px 10px 10px;
    border: 0;
    border-radius: 0;
  }

  body.mobile-input-mode .mobile-play-summary {
    margin-bottom: 7px;
    padding-block: 7px;
  }

  body.mobile-input-mode .current-instruction,
  body.mobile-input-mode .word-input-label,
  body.mobile-input-mode .secondary-actions,
  body.mobile-input-mode .anvil-top,
  body.mobile-input-mode .anvil-base {
    display: none;
  }

  body.mobile-input-mode .word-input {
    height: 48px;
    font-size: 1.4rem;
  }

  body.mobile-input-mode .primary-button {
    margin-top: 7px;
    padding-block: 9px;
  }

  body.mobile-input-mode .feedback,
  body.mobile-input-mode .hint-text {
    min-height: 1em;
    margin-top: 5px;
    font-size: 0.76rem;
  }
}
