:root {
  --ink: #1a140c;
  --paper: #f3e6c8;
  --paper2: #e8d4a8;
  --wood: #6b3f1a;
  --gold: #c9a227;
  --gold2: #e0c040;
  --sea: #0b2836;
  --leaf: #3fa046;
  --hp: #d45a3a;
  --st: #3a9ad4;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sea); }
html, body { touch-action: none; overscroll-behavior: none; }
body {
  font-family: "Noto Sans SC", "Segoe UI", sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#btn-bag { display: none; }
#view {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  background: #0a2430;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.pixel-panel {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper2) 100%);
  border: 3px solid var(--wood);
  box-shadow: 0 0 0 2px var(--gold), 4px 6px 0 rgba(0,0,0,.35);
  border-radius: 2px;
}
#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 5;
  padding: 10px 12px;
  min-width: 240px;
}
#hud h1 {
  font-family: "Noto Sans SC", "Segoe UI", sans-serif;
  font-size: 15px;
  margin: 0 0 8px;
  letter-spacing: 1px;
  color: var(--wood);
}
.bar-row { display: flex; align-items: center; gap: 8px; margin: 5px 0; font-size: 12px; }
.bar-row span.label { width: 42px; flex: none; }
.bar {
  flex: 1;
  height: 12px;
  background: #3a2a18;
  border: 2px solid var(--wood);
  position: relative;
  overflow: hidden;
}
.bar > i { display: block; height: 100%; }
.bar.hunger > i { background: linear-gradient(180deg, #e07040, var(--hp)); }
.bar.stamina > i { background: linear-gradient(180deg, #7ec8f0, var(--st)); }
.meta { display: flex; gap: 12px; font-size: 12px; margin-top: 6px; }
.meta b { color: var(--wood); }
#toggles { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
button, .btn {
  font-family: inherit;
  font-size: 13px;
  background: #f7efe0;
  border: 2px solid var(--wood);
  color: var(--ink);
  padding: 4px 8px;
  cursor: pointer;
  image-rendering: pixelated;
}
button:hover, .btn:hover { background: #fff8e8; }
button.on { background: #c9e8b0; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
#side {
  position: absolute;
  top: 10px;
  right: 10px;
  bottom: 78px;
  width: 276px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  padding: 8px;
  overflow: hidden;
}
#side h2 { margin: 0 0 6px; font-size: 14px; }
#bag {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 72px;
  align-content: start;
  gap: 4px;
  overflow: auto;
  flex: 1;
}
.slot {
  background: #d8c49a;
  border: 2px solid var(--wood);
  height: 72px;
  min-height: 72px;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot.sel { outline: 3px solid var(--gold2); background: #fff1c4; }
.slot canvas, .slot img { width: 48px; height: 48px; image-rendering: pixelated; }
.slot .n {
  position: absolute;
  right: 3px; bottom: 1px;
  font-size: 11px; font-weight: 700;
}
.slot .nm {
  position: absolute;
  left: 3px; top: 1px;
  font-size: 9px;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
}
#actions {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  gap: 8px;
  padding: 8px;
  white-space: nowrap;
}
#actions button { min-width: 72px; font-weight: 700; padding: 8px 10px; }
#actions button.primary { background: #c9e8b0; }
#joy {
  position: absolute;
  left: 18px;
  bottom: 86px;
  width: 140px;
  height: 140px;
  z-index: 8;
  touch-action: none;
  user-select: none;
}
#joy-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(26, 20, 12, .38);
  border: 4px solid rgba(201, 162, 39, .75);
  box-shadow: inset 0 0 0 3px rgba(107, 63, 26, .55), 0 4px 0 rgba(0,0,0,.25);
}
#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f3e6c8, #c9a227 55%, #6b3f1a);
  border: 3px solid #3a2010;
  box-shadow: 0 3px 0 #3a2010;
  pointer-events: none;
}
#hint {
  display: none;
}
#tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  padding: 8px 10px;
  max-width: 220px;
  display: none;
  font-size: 13px;
}
#tooltip b { display: block; font-size: 14px; }
#tooltip .py { color: #6b3f1a; font-size: 12px; margin-top: 2px; }
#tooltip .sub { color: #4a3a28; font-size: 12px; margin-top: 4px; }
#toast {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 8px 16px;
  display: none;
  font-weight: 700;
}
#toast.show { display: block; }
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(8, 20, 28, .55);
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-back.show { display: flex; }
.modal {
  width: min(520px, 92vw);
  max-height: 84vh;
  overflow: auto;
  padding: 16px;
}
.modal h3 { margin: 0 0 10px; font-size: 18px; }
.modal .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed #c9b080; }
.list-item { display: flex; align-items: center; gap: 8px; }
.list-item canvas { width: 40px; height: 40px; image-rendering: pixelated; }
.fish-wrap { padding: 12px 0 6px; }
.fish-bar {
  position: relative;
  height: 28px;
  background: #3a2a18;
  border: 3px solid var(--wood);
  overflow: hidden;
}
.fish-green {
  position: absolute;
  top: 0; bottom: 0;
  background: #3fa046;
  opacity: .9;
}
.fish-needle {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 4px;
  background: #fff8e8;
  box-shadow: 0 0 0 1px #1a140c;
}
.fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 25;
}
.art-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.art-grid img { width: 100%; image-rendering: pixelated; background: #2a3830; }
.mode-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 6px 12px;
  display: none;
  font-weight: 700;
}
.mode-banner.show { display: block; }
#equip {
  font-size: 12px;
  margin-top: 6px;
}
.night-note { font-size: 11px; opacity: .75; margin-top: 4px; }
input[type="number"] {
  width: 88px;
  padding: 4px;
  font: inherit;
  border: 2px solid var(--wood);
  background: #fff8e8;
}
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--wood); }
@media (max-width: 820px) {
  #hud {
    min-width: 0;
    width: calc(100vw - 16px);
    left: 8px;
    right: 8px;
    top: 8px;
    padding: 6px 8px;
    max-height: 42vh;
    overflow: auto;
  }
  #hud h1 { font-size: 9px; margin-bottom: 4px; }
  .bar-row { margin: 3px 0; font-size: 11px; }
  #equip, #how-line, #hint { display: none; }
  #toggles { gap: 4px; margin-top: 4px; }
  #toggles button { font-size: 12px; padding: 7px 8px; min-height: 36px; }
  #btn-bag { display: inline-block; background: #c9e8b0; }
  #side {
    display: none;
    top: auto;
    left: 8px;
    right: 8px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    width: auto;
    height: 36vh;
    z-index: 16;
  }
  #side.open { display: flex; }
  #actions {
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    transform: none;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px;
  }
  #actions button {
    flex: 1 1 30%;
    min-width: 0;
    min-height: 44px;
    font-size: 15px;
    padding: 8px 6px;
  }
  .modal { width: min(520px, 96vw); max-height: 80vh; padding: 12px; }
  .fish-bar { height: 40px; }
  #toast { top: 46%; }
  #joy {
    left: 10px;
    bottom: calc(102px + env(safe-area-inset-bottom, 0px));
    width: 128px;
    height: 128px;
  }
  #joy-knob { width: 54px; height: 54px; margin: -27px 0 0 -27px; }
}