:root {
  --bg: #3d2918;
  --panel: rgba(36, 22, 12, 0.82);
  --panel-solid: #4a3018;
  --text: #f6ecd0;
  --muted: #d9c59a;
  --gold: #f0c44a;
  --gold-dark: #c4921a;
  --wood: #6b3e26;
  --flesh: #f3dcb0;
  --water: #3d7ea6;
  --danger: #c44b2b;
  --safe-t: max(10px, env(safe-area-inset-top));
  --safe-r: max(10px, env(safe-area-inset-right));
  --safe-b: max(12px, env(safe-area-inset-bottom));
  --safe-l: max(10px, env(safe-area-inset-left));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

#app, canvas#c {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden, [hidden] { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px);
  background:
    radial-gradient(ellipse at 50% 18%, rgba(240, 196, 74, 0.16), transparent 55%),
    rgba(18, 10, 2, 0.28);
  pointer-events: auto;
  overflow: auto;
  touch-action: pan-y;
}

.screen.overlay { background: rgba(12, 6, 0, 0.62); z-index: 30; }

.menu-card, .sheet {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid rgba(240, 196, 74, 0.28);
  border-radius: 22px;
  padding: 22px 18px 18px;
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.35);
  text-align: center;
}

.menu-card.slim, .sheet.slim { width: min(380px, 100%); }
.sheet {
  width: min(520px, 100%);
  max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 24px);
  overflow: auto;
  touch-action: pan-y;
  text-align: left;
}

h1, h2 { margin: 0 0 10px; letter-spacing: 0.02em; }
h1 { font-size: clamp(1.7rem, 6vw, 2.15rem); }
h2 { font-size: 1.35rem; }
.kicker { margin: 0; color: var(--gold); text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.72rem; }
.tagline { margin: 0 0 16px; font-size: 1.05rem; }
.hint { margin: 14px 0 0; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.controls-hint { list-style: none; padding: 0; margin: 14px 0 0; color: var(--muted); font-size: 0.84rem; text-align: left; line-height: 1.4; }
.controls-hint li { margin: 0 0 6px; padding-left: 0.2em; }
body.touch-ui .controls-hint .desk,
body:not(.touch-ui) .controls-hint .mob { display: none; }

.btn, .btn-action, .btn-icon {
  font: inherit;
  color: var(--text);
  border: 0;
  cursor: pointer;
  appearance: none;
}

.btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 14px 16px;
  border-radius: 14px;
  font-weight: 650;
  font-size: 1.05rem;
  min-height: 48px;
}

.btn-primary { background: linear-gradient(#f0c44a, #c4921a); color: #2a1a08; }
.btn-secondary { background: #6b3e26; }
.btn-ghost { background: transparent; border: 1px solid rgba(246, 236, 208, 0.25); }
.btn-close { width: auto; margin: 0; padding: 8px 12px; min-height: 40px; font-size: 0.9rem; background: #5a3a22; }
.btn:active { transform: translateY(1px); }

.progress {
  height: 12px;
  border-radius: 99px;
  background: rgba(0,0,0,0.35);
  overflow: hidden;
  margin: 16px 0 8px;
}
#load-bar { height: 100%; width: 0; background: linear-gradient(90deg, #c4921a, #f0c44a); transition: width 0.15s; }

#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud .interactive, #hud button, #hud .hud-panel { pointer-events: auto; }

.hud-panel {
  background: var(--panel);
  border: 1px solid rgba(240, 196, 74, 0.22);
  border-radius: 14px;
  padding: 8px 12px;
  backdrop-filter: blur(8px);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

#hud-top {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 8px);
  right: calc(var(--safe-r) + 56px);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: space-between;
}

#hud-tool {
  position: absolute;
  top: calc(var(--safe-t) + 52px);
  left: calc(var(--safe-l) + 8px);
}

#hud-held {
  position: absolute;
  top: calc(var(--safe-t) + 52px);
  right: calc(var(--safe-r) + 56px);
  width: min(200px, 46vw);
  text-align: left;
}
#held-label { display: block; margin-bottom: 4px; }
#held-quality { display: block; margin-top: 4px; color: var(--muted); font-size: 0.8rem; }

.peel-bar, .det-bar {
  height: 8px;
  border-radius: 99px;
  background: rgba(0,0,0,0.4);
  overflow: hidden;
}
#peel-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #8B5A2B, #F3DCB0);
  transition: width 0.12s;
}

#toast {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border-radius: 14px;
  padding: 10px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  text-align: center;
  max-width: min(320px, 86vw);
}
#toast.show { opacity: 1; }

#prompt {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 118px);
  transform: translateX(-50%);
  white-space: nowrap;
}

#actions {
  position: absolute;
  right: calc(var(--safe-r) + 10px);
  bottom: calc(var(--safe-b) + 10px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.btn-action {
  min-width: 92px;
  min-height: 72px;
  padding: 10px 14px;
  border-radius: 18px;
  background: rgba(36, 22, 12, 0.82);
  border: 1px solid rgba(240, 196, 74, 0.28);
  font-weight: 700;
  font-size: 0.95rem;
  backdrop-filter: blur(8px);
}
.btn-action.btn-peel {
  min-width: 108px;
  min-height: 108px;
  border-radius: 50%;
  background: linear-gradient(#f0c44a, #c4921a);
  color: #2a1a08;
  font-size: 1.05rem;
  border: 0;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
.btn-action.btn-peel.active, .btn-action.held {
  outline: 3px solid #fff4c8;
  transform: scale(0.97);
}

#btn-menu {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  right: calc(var(--safe-r) + 8px);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid rgba(240, 196, 74, 0.22);
  font-size: 1.2rem;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.shop-money { margin: 0 0 12px; color: var(--gold); font-weight: 700; font-size: 1.1rem; }
.shop-list { display: flex; flex-direction: column; gap: 10px; }
.shop-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
  background: rgba(0,0,0,0.22);
  border-radius: 14px;
  padding: 12px;
}
.shop-item h3 { margin: 0; font-size: 1rem; }
.shop-item p { margin: 0; grid-column: 1 / -1; color: var(--muted); font-size: 0.86rem; }
.shop-item .price { color: var(--gold); font-weight: 700; }
.shop-item button {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #c4921a;
  color: #2a1a08;
  font-weight: 700;
  border: 0;
}
.shop-item button:disabled {
  background: #4a3a28;
  color: var(--muted);
}

.quality-line {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
  text-align: left;
  color: var(--muted);
}
.quality-line select {
  font: inherit;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(246,236,208,0.2);
  background: #2a1a10;
  color: var(--text);
}

.win-stats { list-style: none; padding: 0; margin: 8px 0 16px; text-align: left; }
.win-stats li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid rgba(246,236,208,0.12); }

body:not(.touch-ui) .btn-action { min-width: 80px; min-height: 56px; }
body:not(.touch-ui) .btn-action.btn-peel { min-width: 88px; min-height: 88px; }

@media (orientation: landscape) and (max-height: 500px) {
  .menu-card, .sheet { padding: 14px 14px 12px; }
  h1 { font-size: 1.5rem; }
  #hud-top { right: calc(var(--safe-r) + 120px); }
  #hud-held { top: calc(var(--safe-t) + 8px); right: calc(var(--safe-r) + 120px); width: min(180px, 30vw); }
  #actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
    width: min(420px, 70vw);
  }
  .btn-action { min-width: 76px; min-height: 70px; }
  .btn-action.btn-peel { min-width: 84px; min-height: 84px; }
  #prompt { bottom: calc(var(--safe-b) + 96px); }
}

@media (min-width: 900px) {
  .btn-action { min-width: 96px; }
}
