:root {
  color-scheme: light;
  --ink: #2a1c14;
  --paper: #f3e6cf;
  --paper-deep: #e7d3b4;
  --brass: #a67c45;
  --red: #7a2e2a;
  --forest: #2c4634;
  --shadow: 0 18px 50px rgba(42, 28, 20, 0.28);
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", "Apple SD Gothic Neo", "Noto Serif KR", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cbb89a; color: var(--ink); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
}
#crosshair i {
  position: absolute;
  background: #fff;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.55);
}
#crosshair i:nth-child(1) { width: 2px; height: 7px; left: 10px; top: 0; }
#crosshair i:nth-child(2) { width: 2px; height: 7px; left: 10px; bottom: 0; }
#crosshair i:nth-child(3) { width: 7px; height: 2px; top: 10px; left: 0; }
#crosshair i:nth-child(4) { width: 7px; height: 2px; top: 10px; right: 0; }
#crosshair.item i { background: #ffe1a8; }
#crosshair.good i { background: #d9f5c4; }
#crosshair.bad i { background: #ffb1a4; }

#aim {
  position: fixed;
  left: 50%;
  top: calc(50% + 28px);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 3;
  color: #fffaf2;
  background: rgba(22, 16, 12, 0.9);
  border: 1px solid rgba(255, 244, 220, 0.38);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}
#aim:empty { opacity: 0; }
#aim.item { background: rgba(22, 16, 12, 0.92); }
#aim.good { background: rgba(20, 92, 46, 0.94); border-color: rgba(190, 245, 170, 0.7); }
#aim.bad { background: rgba(122, 32, 28, 0.94); border-color: rgba(255, 180, 168, 0.75); }

#toast {
  position: fixed;
  left: 50%;
  top: max(108px, 16%);
  transform: translateX(-50%) translateY(-6px);
  background: rgba(42, 28, 20, 0.88);
  color: var(--paper);
  padding: 8px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.2s ease;
  font-size: 15px;
}
#toast.show { opacity: 1; }

#pops {
  position: fixed;
  left: 50%;
  top: 42%;
  width: 0;
  height: 0;
  z-index: 4;
  pointer-events: none;
}
#pops span {
  position: absolute;
  left: 18px;
  animation: float 700ms ease forwards;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
#pops .good { color: #f2e2a8; }
#pops .bad { color: #ffb1a4; }
@keyframes float {
  to { transform: translateY(-36px); opacity: 0; }
}

#arrow {
  position: fixed;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  z-index: 4;
  pointer-events: none;
  background: #ffd27a;
  clip-path: polygon(0 35%, 55% 35%, 55% 0, 100% 50%, 55% 100%, 55% 65%, 0 65%);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
}
.stats {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  background: #f3e6cf;
  border: 1px solid rgba(166, 124, 69, 0.45);
  padding: 12px 16px 10px;
  min-width: 180px;
  box-shadow: var(--shadow);
}
.stats p { margin: 0 0 4px; font-size: 16px; }
.stats p:last-child { margin-bottom: 0; }
.stats .brand { letter-spacing: 0.16em; font-size: 12px; color: var(--red); margin-bottom: 6px; }

#up-toggle, #keys { pointer-events: auto; }
#up-toggle {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  background: var(--ink);
  color: var(--paper);
  border: 0;
  padding: 10px 14px;
}
#keys {
  position: absolute;
  left: 50%;
  bottom: max(108px, calc(env(safe-area-inset-bottom) + 102px));
  transform: translateX(-50%);
  margin: 0;
  color: #fffaf2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  font-size: 13px;
  pointer-events: none;
  white-space: nowrap;
}

#inventory {
  --slots: 5;
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  pointer-events: none;
  width: min(calc(var(--slots) * 74px), 760px, calc(100vw - 280px));
}
#inv-slots {
  display: flex;
  gap: 6px;
  justify-content: center;
  width: 100%;
  padding: 6px;
  background: rgba(243, 230, 207, 0.88);
  border: 1px solid rgba(166, 124, 69, 0.45);
  box-shadow: 0 10px 28px rgba(42, 28, 20, 0.18);
}
.inv-slot {
  position: relative;
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: 68px;
  height: 78px;
  padding: 4px 2px 3px;
  appearance: none;
  background: rgba(243, 230, 207, 0.94);
  border: 1px solid rgba(166, 124, 69, 0.6);
  box-shadow: 0 8px 18px rgba(42, 28, 20, 0.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink);
  pointer-events: auto;
}
.inv-slot img {
  width: min(46px, 86%);
  height: 42px;
  object-fit: contain;
  border-radius: 4px;
  background: #fffaf2;
  pointer-events: none;
}
.inv-slot b {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.inv-key {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 10px;
  color: #7a6556;
  pointer-events: none;
}
.inv-slot.active {
  border-color: var(--forest);
  box-shadow: 0 0 0 2px var(--forest), 0 8px 18px rgba(42, 28, 20, 0.22);
}
.inv-slot.empty {
  background: rgba(243, 230, 207, 0.28);
  border-style: dashed;
  box-shadow: none;
  pointer-events: none;
}

#upgrade {
  position: fixed;
  top: max(64px, calc(env(safe-area-inset-top) + 56px));
  right: max(16px, env(safe-area-inset-right));
  width: min(320px, calc(100vw - 32px));
  background: var(--paper);
  color: var(--ink);
  z-index: 10;
  box-shadow: var(--shadow);
  border: 1px solid rgba(166, 124, 69, 0.5);
  max-height: min(70vh, 520px);
  overflow: auto;
}
#upgrade header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(42, 28, 20, 0.1);
}
#upgrade h2 { margin: 0; font-size: 18px; font-weight: 600; }
#up-close { background: transparent; border: 0; padding: 4px 6px; }
.up-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(42, 28, 20, 0.08);
}
.up-row b { font-weight: 600; }
.up-row span { grid-column: 1; color: #5c4636; font-size: 13px; }
.up-row button {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  background: var(--forest);
  color: #f6f1e4;
  border: 0;
  padding: 8px 10px;
  min-width: 84px;
}
.up-row button:disabled { background: #b7aa98; color: #efe7da; cursor: default; }

#touch { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#stick {
  pointer-events: auto;
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(243, 230, 207, 0.28);
  border: 2px solid rgba(255, 250, 242, 0.7);
  touch-action: none;
}
#knob {
  position: absolute;
  left: 38px;
  top: 38px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 250, 242, 0.92);
}
#actions {
  pointer-events: auto;
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(28px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 168px;
}
#actions button {
  background: rgba(42, 28, 20, 0.78);
  color: var(--paper);
  border: 1px solid rgba(243, 230, 207, 0.35);
  padding: 14px 8px;
  touch-action: manipulation;
}

#menu, #loading, #win, #hint {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(56, 38, 26, 0.28);
}
#hint {
  background: transparent;
  color: #fffaf2;
  font-size: 20px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
#win { z-index: 20; background: rgba(28, 18, 12, 0.58); }
.win-card { text-align: left; }
.win-kicker {
  margin: 0 0 4px;
  color: var(--forest);
  letter-spacing: 0.16em;
  font-size: 14px;
}
.win-stats {
  list-style: none;
  margin: 4px 0 16px;
  padding: 0;
  display: grid;
  gap: 6px;
}
.win-stats li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 12px;
  background: #fffaf2;
  border: 1px solid rgba(42, 28, 20, 0.1);
}
.win-stats b { font-weight: 600; }
.card {
  width: min(520px, 100%);
  background: var(--paper);
  padding: 28px 28px 22px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(166, 124, 69, 0.45);
}
.card .brand { margin: 0 0 8px; letter-spacing: 0.18em; color: var(--red); font-size: 13px; }
.card h1 { margin: 0 0 10px; font-size: 36px; font-weight: 600; }
.lead { margin: 0 0 8px; line-height: 1.5; }
.save-note { margin: 0 0 16px; color: #5c4636; font-size: 14px; }
.modes { display: grid; gap: 8px; }
.modes button#continue {
  background: var(--forest);
  color: #f6f1e4;
  border-color: transparent;
}
.modes button#continue span { color: rgba(246, 241, 228, 0.84); }
.modes button#continue:hover { background: #243c2c; border-color: transparent; }
.modes button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  background: #fffaf2;
  border: 1px solid rgba(42, 28, 20, 0.14);
  padding: 12px 14px;
}
.modes button:hover { border-color: var(--brass); background: #fff; }
.modes b { font-size: 18px; font-weight: 600; }
.modes span { color: #5c4636; font-size: 14px; }
.bar {
  height: 8px;
  background: rgba(42, 28, 20, 0.12);
  margin: 8px 0 12px;
}
.bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--red);
}

body.touch #keys { display: none; }
body.touch .inv-slot { height: 64px; }
body.touch .inv-slot img { height: 32px; }
body.touch .inv-slot b { font-size: 10px; }
body:not(.touch) #touch { display: none !important; }

[hidden] { display: none !important; }

@media (max-width: 980px) {
  #inventory {
    top: max(108px, calc(env(safe-area-inset-top) + 96px));
    width: min(calc(var(--slots) * 74px), calc(100vw - 16px));
  }
}
@media (max-width: 720px) {
  .card h1 { font-size: 30px; }
  #keys { display: none; }
  .inv-slot { height: 62px; }
  .inv-key { display: none; }
}
