:root {
  --bg-top: #f4ecd5;
  --bg-bottom: #d5e8dc;
  --ink-main: #222018;
  --ink-soft: #4a4738;
  --panel: rgba(252, 249, 238, 0.92);
  --panel-strong: rgba(248, 241, 224, 0.96);
  --panel-border: rgba(67, 78, 52, 0.32);
  --accent: #2f6a45;
  --accent-strong: #1f5032;
  --warm: #af5d2c;
  --danger: #8f2f2f;
  --focus: #e7ab2f;
  --shadow: rgba(17, 20, 10, 0.22);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Avenir Next", "Trebuchet MS", "Gill Sans", sans-serif;
  color: var(--ink-main);
  background:
    radial-gradient(circle at 16% 14%, rgba(255, 250, 227, 0.9), rgba(255, 250, 227, 0) 32%),
    radial-gradient(circle at 80% 16%, rgba(193, 232, 201, 0.45), rgba(193, 232, 201, 0) 36%),
    linear-gradient(170deg, var(--bg-top), var(--bg-bottom));
}

.app-shell {
  width: min(1500px, 100% - 2.2rem);
  margin: 1rem auto 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.top-bar {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: 0 10px 28px var(--shadow);
  padding: 0.9rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.top-bar h1 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(1.45rem, 2.4vw, 2.15rem);
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--ink-soft);
  font-size: 0.97rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.btn {
  border: 1px solid rgba(54, 67, 42, 0.35);
  background: linear-gradient(180deg, #fffef8, #ede7d2);
  color: #262113;
  border-radius: 999px;
  padding: 0.46rem 0.85rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(18, 25, 10, 0.18);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(180deg, #2f6a45, #245438);
  color: #f4f7ea;
  border-color: rgba(17, 41, 25, 0.5);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #36794e, #255536);
}

.btn:focus-visible,
.touch-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 0.8rem;
  align-items: start;
}

.canvas-column {
  min-width: 0;
}

.canvas-frame {
  position: relative;
  background: #151c14;
  border: 1px solid rgba(31, 46, 31, 0.5);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 15px 30px rgba(11, 16, 8, 0.35);
}

#game-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  display: block;
  background: #1c281f;
}

.interaction-hint {
  position: absolute;
  left: 0.9rem;
  bottom: 0.8rem;
  max-width: calc(100% - 1.8rem);
  padding: 0.48rem 0.66rem;
  border-radius: 10px;
  background: rgba(14, 19, 13, 0.74);
  color: #eef4df;
  font-size: 0.86rem;
  min-height: 2.05rem;
  display: flex;
  align-items: center;
  transition: opacity 140ms ease;
  opacity: 0;
}

.interaction-hint.show {
  opacity: 1;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: left;
  padding: clamp(1rem, 4vw, 2.6rem);
  background:
    linear-gradient(170deg, rgba(22, 29, 19, 0.84), rgba(32, 39, 25, 0.85)),
    radial-gradient(circle at 20% 15%, rgba(98, 135, 72, 0.36), transparent 48%);
  color: #f7f8ef;
}

.overlay > * {
  width: min(700px, 100%);
}

.overlay h2 {
  margin: 0 0 0.65rem;
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  font-family: "Palatino Linotype", "Book Antiqua", serif;
}

.overlay p {
  line-height: 1.45;
}

.overlay-note {
  color: #dbe5cc;
  font-size: 0.94rem;
  margin-bottom: 1.1rem;
}

.instruction-list {
  margin: 0.75rem 0;
  padding-left: 1.1rem;
  color: #e6f0d4;
}

.instruction-list li {
  margin-bottom: 0.3rem;
}

.hidden {
  display: none !important;
}

.dialogue {
  position: absolute;
  left: 50%;
  bottom: 0.85rem;
  transform: translateX(-50%);
  width: min(860px, calc(100% - 1.1rem));
  border-radius: 14px;
  border: 1px solid rgba(34, 44, 21, 0.55);
  background: linear-gradient(140deg, rgba(249, 244, 225, 0.98), rgba(240, 234, 211, 0.98));
  box-shadow: 0 12px 30px rgba(11, 16, 8, 0.45);
  padding: 0.7rem;
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 0.65rem;
}

#dialogue-portrait {
  width: 100%;
  height: 118px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(46, 56, 31, 0.4);
  background: #d9d5c6;
}

.dialogue-body h3 {
  margin: 0;
  font-size: 1.08rem;
}

.dialogue-body p {
  margin: 0.38rem 0 0.58rem;
  min-height: 3.7em;
  line-height: 1.35;
}

.dialogue-actions {
  display: flex;
  gap: 0.42rem;
}

.mobile-controls {
  display: none;
  position: absolute;
  inset: auto 0.55rem 0.55rem 0.55rem;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.dpad,
.touch-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.dpad-row {
  display: flex;
  gap: 0.35rem;
}

.touch-btn {
  pointer-events: auto;
  border: 1px solid rgba(245, 245, 238, 0.34);
  background: rgba(28, 34, 22, 0.72);
  color: #eef4dd;
  border-radius: 12px;
  padding: 0.5rem 0.68rem;
  min-width: 3.1rem;
  font-size: 0.82rem;
  touch-action: manipulation;
}

.touch-btn.active {
  background: rgba(49, 105, 67, 0.78);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.panel-card {
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: var(--panel-strong);
  box-shadow: 0 6px 18px rgba(20, 24, 12, 0.13);
  padding: 0.74rem 0.8rem;
}

.panel-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
  font-family: "Palatino Linotype", "Book Antiqua", serif;
}

.objective-title {
  margin: 0;
  color: var(--accent-strong);
  font-weight: 700;
}

.objective-text,
.objective-progress,
.stat-line {
  margin: 0.2rem 0;
  color: #393625;
  line-height: 1.35;
}

.objective-progress {
  color: var(--warm);
  font-weight: 600;
}

.quest-list,
.inventory-list {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.35rem;
}

.quest-list li,
.inventory-list li {
  font-size: 0.92rem;
  line-height: 1.3;
}

.quest-list li.current {
  color: var(--accent-strong);
  font-weight: 700;
}

.quest-list li.done {
  color: #4c5e42;
}

.quest-list li.locked {
  color: #7c7a70;
}

kbd {
  border: 1px solid rgba(238, 231, 205, 0.5);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0 0.32rem;
  background: rgba(37, 45, 26, 0.82);
  color: #f7fae7;
  font-size: 0.82rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip: rect(0, 0, 0, 0);
  overflow: hidden;
}

@media (max-width: 1220px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    order: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 1rem, 1200px);
    margin-top: 0.6rem;
  }

  .top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .dialogue {
    grid-template-columns: 90px minmax(0, 1fr);
  }

  #dialogue-portrait {
    height: 90px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }
}

@media (pointer: coarse) and (max-width: 980px) {
  .mobile-controls {
    display: flex;
  }

  #interaction-hint {
    bottom: 5.35rem;
  }
}
