:root {
  --ink: #3b2a1a;
  --paper: #f4ead6;
  --sea: #123a5c;
  --accent: #e07a3c;
  --panel: rgba(244, 234, 214, 0.94);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--sea);
  color: var(--ink);
  font: 15px/1.2 system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#hud {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid rgba(59, 42, 26, 0.2);
}

.stat { display: flex; flex-direction: column; }
.stat.right { text-align: right; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.6; }
.value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.caprow { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.caprow.done { visibility: hidden; }
.cap { font-size: 10px; font-weight: 600; opacity: 0.6; font-variant-numeric: tabular-nums; white-space: nowrap; }
.capbar { flex: 1; height: 4px; border-radius: 2px; background: rgba(59, 42, 26, 0.12); overflow: hidden; }
#cap-fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width 0.15s; }
.value.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 40% { transform: scale(1.15); color: var(--accent); } }

.tide { display: flex; flex-direction: column; gap: 4px; }
.tide-text { font-size: 13px; text-align: center; font-weight: 600; }
.gauge {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: rgba(59, 42, 26, 0.12);
  overflow: hidden;
}
#gauge-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 50%;
  background: linear-gradient(90deg, #3d8fb0, #1f5f8a);
  border-radius: 5px;
}
#gauge-mark {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--ink); opacity: 0.5; left: 50%;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#map {
  display: block;
  touch-action: none;
  image-rendering: auto;
}

#toast {
  position: absolute;
  top: 14px; left: 50%;
  transform: translate(-50%, -8px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(10, 30, 50, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.chip {
  position: absolute;
  border: none;
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  box-shadow: 0 2px 8px rgba(10, 30, 50, 0.2);
}
#carry {
  left: 10px; bottom: 10px;
  padding: 7px 10px;
  min-width: 112px;
  display: grid;
  grid-template-columns: auto auto;
  justify-content: space-between;
  gap: 2px 10px;
  pointer-events: none;
}
#carry-text { font-variant-numeric: tabular-nums; }
#carry.full { background: var(--accent); color: #fff; animation: nudge 0.9s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(-3px); } }
.carrybar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: rgba(59, 42, 26, 0.15); overflow: hidden; }
#carry-fill { height: 100%; width: 0; background: #b98a4a; }
#carry.full #carry-fill { background: #fff; }
#contours { right: 10px; bottom: 10px; padding: 9px 12px; }
#contours.on { background: var(--ink); color: var(--paper); }

#toolbar button { position: relative; }
.dot {
  position: absolute; top: 7px; right: 9px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fffaf0;
}
#toolbar button.active .dot { border-color: var(--accent); background: #fff; }

dialog.sheet {
  margin: auto auto 0;
  width: 100%;
  max-width: 520px;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(14px + env(safe-area-inset-bottom));
  max-height: 75dvh;
}
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; font-size: 17px; }
.sheet-sand { font-size: 14px; }
#shop-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 55dvh; }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fffaf0;
  border: 1.5px solid rgba(59, 42, 26, 0.18);
}
.item .name { font-weight: 700; }
.item .desc { font-size: 13px; opacity: 0.7; grid-column: 1; }
.item button {
  grid-row: 1 / span 2; grid-column: 2;
  min-width: 84px; min-height: 44px;
  border: none; border-radius: 10px;
  background: var(--accent); color: #fff;
  font: inherit; font-weight: 700;
}
.item button:disabled { background: rgba(59, 42, 26, 0.15); color: rgba(59, 42, 26, 0.55); }
.sheet .close { width: 100%; margin-top: 12px; }

#toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border-top: 1px solid rgba(59, 42, 26, 0.2);
}

#toolbar button, dialog button {
  flex: 1;
  min-height: 48px;
  border: 1.5px solid rgba(59, 42, 26, 0.35);
  border-radius: 12px;
  background: #fffaf0;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
}
#toolbar button.icon { flex: 0 0 52px; font-size: 22px; }
#toolbar button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
#toolbar button.toggle.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

dialog {
  border: none;
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  padding: 18px;
  width: min(320px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(10, 30, 50, 0.5); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog p { margin: 0 0 6px; font-weight: 700; text-align: center; }
#reset { color: #a3361a; }
