:root {
  color-scheme: light;
  --ink: #201c1a;
  --muted: #6e6158;
  --cream: #f5e5cf;
  --paper: #fffaf1;
  --red: #a82f2f;
  --red-deep: #702324;
  --green: #637843;
  --line: rgba(58, 45, 38, 0.18);
  --shadow: 0 28px 70px rgba(67, 43, 29, 0.18);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 10%, rgba(255, 255, 255, 0.8), transparent 42rem),
    var(--cream);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button { font: inherit; }

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 54px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.dialog-eyebrow {
  margin: 0 0 5px;
  color: var(--red);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 4vw, 3.35rem);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 470px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 241, 0.78);
  box-shadow: 0 9px 26px rgba(70, 48, 32, 0.08);
  color: var(--muted);
  font-size: 0.83rem;
  backdrop-filter: blur(10px);
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(99, 120, 67, 0.14);
}

.game-card {
  overflow: hidden;
  border: 1px solid rgba(59, 43, 35, 0.16);
  border-radius: 28px;
  background: rgba(255, 250, 241, 0.76);
  box-shadow: var(--shadow);
}

.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  min-height: 320px;
  overflow: hidden;
  background: #f5dfc5;
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}

.toolbar {
  position: absolute;
  z-index: 10;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 7px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 15px;
  background: rgba(24, 21, 20, 0.82);
  box-shadow: 0 10px 30px rgba(20, 16, 14, 0.22);
  backdrop-filter: blur(10px);
}

.toolbar button,
.interact-button,
.dialog-actions button {
  min-width: 38px;
  min-height: 38px;
  border: 0;
  border-radius: 10px;
  background: #fff7e9;
  color: #28211e;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.toolbar button:hover,
.interact-button:hover,
.dialog-actions button:hover { transform: translateY(-1px); }

.toolbar button:active,
.interact-button:active,
.dialog-actions button:active { transform: translateY(1px); }

.toolbar button[aria-pressed="true"] {
  background: #c54a42;
  color: white;
}

.interact-button {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 0 18px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  background: var(--red);
  color: white;
  box-shadow: 0 12px 28px rgba(80, 27, 26, 0.3);
}

.interact-button:hover { transform: translateX(-50%) translateY(-1px); }
.interact-button:active { transform: translateX(-50%) translateY(1px); }

.touch-pad {
  position: absolute;
  z-index: 11;
  left: 14px;
  bottom: 14px;
  display: none;
  grid-template: repeat(3, 43px) / repeat(3, 43px);
  gap: 4px;
  user-select: none;
}

.touch-pad button {
  border: 1px solid rgba(255,255,255,.36);
  border-radius: 12px;
  background: rgba(25, 22, 21, 0.82);
  color: white;
  font-size: 0.9rem;
  touch-action: none;
  backdrop-filter: blur(8px);
}

.touch-pad button.is-held { background: var(--red); }
.touch-up { grid-area: 1 / 2; }
.touch-left { grid-area: 2 / 1; }
.touch-down { grid-area: 2 / 2; }
.touch-right { grid-area: 2 / 3; }

.inventory {
  position: absolute;
  z-index: 10;
  top: 14px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: calc(100% - 260px);
  pointer-events: none;
}

.inventory[hidden] { display: none; }

.inventory-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 7px 11px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 999px;
  background: rgba(24, 21, 20, 0.82);
  color: #fff7e9;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-shadow: 0 8px 22px rgba(20, 16, 14, 0.2);
  backdrop-filter: blur(10px);
}

.scene-banner {
  position: absolute;
  z-index: 9;
  top: 18%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 26px 14px;
  border: 2px solid rgba(255, 247, 233, 0.9);
  border-radius: 16px;
  background: rgba(24, 21, 20, 0.86);
  color: #fff7e9;
  white-space: nowrap;
  box-shadow: 0 16px 40px rgba(20, 16, 14, 0.3);
  opacity: 0;
  transform: translate(-50%, -8px);
  pointer-events: none;
  transition: opacity 260ms ease, transform 260ms ease;
}

.scene-banner.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.scene-banner-eyebrow {
  color: #f2a7a0;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.scene-banner-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.3rem, 3vw, 1.9rem);
  letter-spacing: -0.03em;
}

.loading-card {
  position: absolute;
  z-index: 30;
  inset: 50% auto auto 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translate(-50%, -50%);
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(29, 25, 23, 0.9);
  color: white;
  font-size: 0.86rem;
  box-shadow: 0 14px 38px rgba(30, 22, 19, 0.26);
}

.loading-card[hidden] { display: none; }

.loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

code {
  padding: 0.1em 0.35em;
  border-radius: 5px;
  background: rgba(92, 64, 46, 0.09);
  color: var(--red-deep);
}

.poi-dialog {
  width: min(470px, calc(100% - 28px));
  padding: 28px;
  border: 1px solid rgba(61, 42, 33, 0.16);
  border-radius: 22px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 34px 90px rgba(34, 23, 18, 0.35);
}

.poi-dialog::backdrop {
  background: rgba(29, 21, 18, 0.56);
  backdrop-filter: blur(6px);
}

.poi-dialog h2 {
  margin: 0 0 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  letter-spacing: -0.035em;
}

.poi-dialog > p:not(.dialog-eyebrow) {
  color: var(--muted);
  line-height: 1.65;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: rgba(89, 63, 49, 0.08);
  color: var(--ink);
  font-size: 1.45rem;
  cursor: pointer;
}

.poi-dialog > p[hidden] { display: none; }

.dialog-list {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.dialog-list[hidden] { display: none; }

.dialog-list li {
  padding: 9px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
}

.dialog-actions button {
  padding: 0 15px;
  background: var(--red);
  color: white;
}

.dialog-actions button.is-secondary {
  border: 1px solid rgba(58, 45, 38, 0.2);
  background: #fff7e9;
  color: var(--ink);
}

.dialog-actions.is-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dialog-actions.is-menu button:last-child:nth-child(odd) { grid-column: 1 / -1; }

.dialog-actions button:focus-visible {
  outline: 3px solid rgba(168, 47, 47, 0.45);
  outline-offset: 2px;
}

.help-dialog dl { margin: 18px 0 0; }
.help-dialog dl div {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 15px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.help-dialog dt { font-weight: 800; }
.help-dialog dd { margin: 0; color: var(--muted); }

@media (pointer: coarse), (max-width: 760px) {
  .touch-pad { display: grid; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .status-pill { width: 100%; max-width: none; }
  .toolbar { top: 10px; right: 10px; }
  .toolbar button { min-width: 34px; min-height: 34px; font-size: .78rem; }
  .interact-button { bottom: 18px; }
}

@media (max-width: 500px) {
  .app-shell { width: min(100%, calc(100% - 14px)); padding-top: 15px; }
  .inventory { top: 10px; left: 10px; max-width: calc(100% - 120px); }
  .scene-banner { top: 22%; padding: 9px 18px 11px; border-radius: 13px; }
  .inventory-chip { max-width: 180px; padding: 5px 9px; font-size: 0.72rem; }
  .game-card { border-radius: 19px; }
  .toolbar #resetButton,
  .toolbar #debugButton { display: none; }
  .touch-pad { grid-template: repeat(3, 39px) / repeat(3, 39px); }
  .interact-button { left: auto; right: 12px; transform: none; }
  .interact-button:hover, .interact-button:active { transform: none; }
}
