:root {
  --page-bg: #0f1a0f;
  --canvas-bg: #1a2e1a;
  --canvas-border: #2e4b2e;
  --panel-bg: #1b2a1b;
  --panel-text: #d0e8cf;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  padding: 12px;
  background: radial-gradient(circle at top, #233723 0%, var(--page-bg) 60%);
  color: var(--panel-text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.game-shell {
  position: relative;
  overflow: hidden;
  width: min(calc(100vw - 24px), 1464px);
  height: min(calc(100vh - 24px), 984px);
  display: flex;
  margin: 0 auto;
  padding: 12px;
  border-radius: 8px;
  background: linear-gradient(180deg, #243824 0%, var(--panel-bg) 100%);
  border: 1px solid #3b5f3b;
}

.title-screen {
  position: absolute;
  inset: 20px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(96, 142, 98, 0.14) 0%, rgba(8, 14, 8, 0.16) 42%, rgba(4, 8, 4, 0.7) 100%);
  backdrop-filter: blur(8px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.title-screen.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.99);
}

.title-screen__panel {
  width: min(780px, 100%);
  padding: 32px 34px 28px;
  border-radius: 28px;
  border: 1px solid rgba(188, 220, 189, 0.2);
  background:
    radial-gradient(circle at top left, rgba(104, 153, 110, 0.12) 0%, rgba(0, 0, 0, 0) 32%),
    linear-gradient(180deg, rgba(24, 37, 24, 0.96) 0%, rgba(11, 19, 12, 0.96) 100%);
  box-shadow:
    0 28px 70px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(232, 246, 227, 0.05);
}

.title-screen__eyebrow {
  color: #a8c6a8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.title-screen__title {
  margin: 12px 0 0;
  color: #f0f7ea;
  font-size: clamp(34px, 4vw, 54px);
  line-height: 1.02;
  letter-spacing: -0.03em;
}

.title-screen__body {
  max-width: 620px;
  margin: 16px 0 0;
  color: #cadecc;
  font-size: 18px;
  line-height: 1.55;
}

.title-screen__objective-card {
  margin-top: 24px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid rgba(188, 220, 189, 0.14);
  background: linear-gradient(180deg, rgba(34, 51, 34, 0.78) 0%, rgba(23, 36, 23, 0.78) 100%);
}

.title-screen__objective-label {
  color: #9fc09f;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.title-screen__objective-body {
  margin-top: 8px;
  color: #edf6e6;
  font-size: 16px;
  line-height: 1.5;
}

.title-screen__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.title-screen__chip {
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(190, 222, 192, 0.14);
  background: rgba(33, 48, 33, 0.88);
  color: #dfedd8;
  font-size: 13px;
  line-height: 1;
}

.title-screen__chip strong {
  color: #f0f7ea;
  margin-right: 6px;
}

.title-screen__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 28px;
}

.title-screen__start-button {
  padding: 13px 18px;
  border: 1px solid rgba(202, 231, 176, 0.26);
  border-radius: 14px;
  background: linear-gradient(180deg, #5f8a4d 0%, #486c39 100%);
  color: #f7ffef;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease;
}

.title-screen__start-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
  border-color: rgba(227, 248, 209, 0.42);
}

.title-screen__hint {
  color: #adc5ad;
  font-size: 13px;
}

.title-screen__credit {
  margin-top: 6px;
  color: #8fae8f;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.title-screen__hint kbd {
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(188, 220, 189, 0.16);
  background: rgba(26, 38, 26, 0.92);
  color: #eef8e7;
  font: inherit;
  font-size: 12px;
}

.title-screen__save-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  flex-basis: 100%;
  margin-top: 4px;
}

.title-screen__save-button {
  padding: 8px 13px;
  border: 1px solid rgba(202, 231, 176, 0.2);
  border-radius: 11px;
  background: rgba(26, 38, 26, 0.72);
  color: #d7e8cf;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease;
}

.title-screen__save-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  border-color: rgba(227, 248, 209, 0.36);
}

.title-screen__save-status {
  flex-basis: 100%;
  min-height: 16px;
  margin-top: 2px;
  color: #adc5ad;
  font-size: 12px;
}

.title-screen__start-button.is-hidden,
.title-screen__save-button.is-hidden {
  display: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--canvas-bg);
  border: 2px solid var(--canvas-border);
  image-rendering: pixelated;
}

@media (max-width: 760px) {
  .title-screen {
    inset: 12px;
    padding: 12px;
  }

  .title-screen__panel {
    padding: 24px 20px 22px;
  }

  .title-screen__body {
    font-size: 16px;
  }

  .title-screen__actions {
    align-items: stretch;
    flex-direction: column;
  }

  .title-screen__start-button {
    width: 100%;
  }
}

.spirit-panel {
  position: absolute;
  left: 24px;
  bottom: 24px;
  width: min(520px, calc(100% - 48px));
  max-height: calc(100% - 48px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 18px 16px;
  border: 1px solid rgba(190, 226, 194, 0.26);
  border-radius: 18px;
  background:
    radial-gradient(circle at top left, rgba(106, 160, 110, 0.12) 0%, rgba(0, 0, 0, 0) 34%),
    linear-gradient(180deg, rgba(20, 31, 20, 0.97) 0%, rgba(11, 20, 12, 0.96) 100%);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(236, 250, 230, 0.04);
  backdrop-filter: blur(8px);
  color: #deeedb;
  z-index: 4;
}

.spirit-panel[hidden] {
  display: none;
}

.spirit-panel__header,
.spirit-panel__header-actions,
.spirit-panel__composer-actions {
  display: flex;
  align-items: center;
}

.spirit-panel__header {
  justify-content: space-between;
  gap: 12px;
}

.spirit-panel__title-wrap {
  min-width: 0;
}

.spirit-panel__title {
  color: #f4faef;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.spirit-panel__subtitle {
  margin-top: 4px;
  max-width: 320px;
  color: #afc7b1;
  font-size: 13px;
  line-height: 1.4;
}

.spirit-panel__header-actions {
  gap: 8px;
}

.spirit-panel__close-button,
.spirit-panel__ghost-button,
.spirit-panel__action-button,
.spirit-panel__prompt-chip {
  border: 1px solid rgba(184, 220, 188, 0.22);
  border-radius: 12px;
  background: rgba(37, 56, 37, 0.82);
  color: #eff6e6;
  font: inherit;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.spirit-panel__close-button,
.spirit-panel__ghost-button {
  padding: 8px 11px;
  font-size: 12px;
}

.spirit-panel__close-button {
  min-width: 38px;
}

.spirit-panel__route {
  padding: 12px 14px;
  border: 1px solid rgba(184, 220, 188, 0.16);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(32, 49, 32, 0.82) 0%, rgba(24, 39, 24, 0.78) 100%);
}

.spirit-panel__route-label {
  margin-bottom: 6px;
  color: #9fbd9f;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.spirit-panel__route-body {
  color: #ebf5e0;
  font-size: 14px;
  line-height: 1.45;
}

.spirit-panel__composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.spirit-panel__textarea {
  width: 100%;
  border: 1px solid rgba(184, 220, 188, 0.18);
  border-radius: 14px;
  background: rgba(10, 16, 10, 0.88);
  color: #eef8ea;
  font: inherit;
  min-height: 94px;
  padding: 14px;
  resize: vertical;
  line-height: 1.45;
}

/* Turnstile widget: collapses to nothing in interaction-only mode until a
   challenge is actually shown, so it doesn't add empty space to the composer. */
.spirit-panel__turnstile:empty {
  display: none;
}

.spirit-panel__turnstile {
  display: flex;
  justify-content: center;
}

.spirit-panel__action-button {
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 600;
}

.spirit-panel__quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.spirit-panel__prompt-chip {
  padding: 8px 11px;
  font-size: 12px;
  line-height: 1.2;
}

.spirit-panel__transcript {
  min-height: 168px;
  max-height: min(36vh, 320px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(184, 220, 188, 0.14);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(8, 15, 8, 0.86) 0%, rgba(15, 23, 14, 0.84) 100%);
}

.spirit-panel__message {
  padding: 11px 13px;
  border-radius: 14px;
  line-height: 1.5;
}

.spirit-panel__message--assistant {
  background: linear-gradient(180deg, rgba(38, 61, 37, 0.92) 0%, rgba(31, 49, 30, 0.92) 100%);
  border: 1px solid rgba(184, 220, 188, 0.18);
}

.spirit-panel__message--user {
  background: linear-gradient(180deg, rgba(37, 48, 72, 0.88) 0%, rgba(30, 39, 58, 0.88) 100%);
  border: 1px solid rgba(176, 196, 238, 0.18);
}

.spirit-panel__message--system {
  background: linear-gradient(180deg, rgba(72, 54, 29, 0.88) 0%, rgba(60, 45, 24, 0.88) 100%);
  border: 1px solid rgba(229, 198, 126, 0.18);
}

.spirit-panel__message-label {
  margin-bottom: 5px;
  color: #b8d7b4;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.spirit-panel__message-body {
  white-space: pre-wrap;
  font-size: 14px;
}

.spirit-panel__footnote {
  color: #9eb89f;
  font-size: 12px;
  line-height: 1.4;
  padding-top: 2px;
}

.spirit-panel__ghost-button:hover,
.spirit-panel__close-button:hover,
.spirit-panel__action-button:hover,
.spirit-panel__prompt-chip:hover {
  background: rgba(51, 77, 51, 0.96);
  border-color: rgba(194, 230, 198, 0.34);
  transform: translateY(-1px);
}

.spirit-panel__action-button:disabled {
  opacity: 0.68;
  cursor: progress;
}

@media (max-width: 980px) {
  .spirit-panel {
    left: 16px;
    right: 16px;
    width: auto;
    bottom: 16px;
    max-height: calc(100% - 32px);
  }
}
