:root {
  --ink: #f4f1e8;
  --ink-soft: rgba(244, 241, 232, 0.72);
  --glass: rgba(24, 32, 28, 0.62);
  --glass-line: rgba(255, 255, 255, 0.14);
  --card: #f6f2e7;
  --card-ink: #26302a;
  --card-soft: #5d675f;
  --accent: #2f7d6b;
  --accent-ink: #ffffff;
  --line: rgba(38, 48, 42, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #151b18; color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none;
}

#stage {
  position: relative; height: 100dvh; max-width: 520px; margin: 0 auto;
  overflow: hidden; background: #2a332d;
}

#creek { display: block; width: 100%; height: 100%; touch-action: none; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid #ffd27a; outline-offset: 2px; }

.pill {
  position: absolute; display: flex; align-items: center; gap: 10px;
  background: var(--glass); border: 1px solid var(--glass-line); border-radius: 999px;
  -webkit-backdrop-filter: blur(14px) saturate(1.3); backdrop-filter: blur(14px) saturate(1.3);
  color: var(--ink); box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
}

#status { top: calc(var(--safe-top) + 12px); left: 12px; padding: 8px 12px 8px 14px; max-width: calc(100% - 24px); text-align: left; }
.status-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.status-text strong { font-size: 15px; font-weight: 650; }
#status-sub { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: #c9b48a; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12); }
.dot[data-state="trickle"], .dot[data-state="waking"] { background: #8fd0c2; }
.dot[data-state="flowing"] { background: #4fb8d6; }
.dot[data-state="high"], .dot[data-state="flood"] { background: #3d8ef0; }
.dot[data-state="pretend"] { background: #ffd27a; }

.chip { top: calc(var(--safe-top) + 70px); left: 12px; padding: 9px 14px; font-size: 14px; font-weight: 600; }

#tools {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 12px); transform: translateX(-50%);
  display: flex; gap: 4px; padding: 5px; width: max-content; max-width: calc(100% - 16px);
  background: var(--glass); border: 1px solid var(--glass-line); border-radius: 22px;
  -webkit-backdrop-filter: blur(14px) saturate(1.3); backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.25);
}
#tools button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 68px; min-height: 54px; padding: 7px 8px 6px; border-radius: 17px;
  font-size: 11.5px; font-weight: 600; color: var(--ink-soft); white-space: nowrap;
}
#tools svg { width: 22px; height: 22px; }
#tools button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.92); color: #20302a; }
#tools #rain-btn[aria-pressed="true"] { background: #ffd27a; color: #3b2c06; }

#toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 92px); transform: translate(-50%, 8px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px; text-align: center;
  background: rgba(20, 26, 23, 0.86); font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog {
  border: 0; padding: 0; background: transparent; color: var(--card-ink);
  width: 100%; max-width: 520px; max-height: 100dvh; margin: auto auto 0;
}
dialog::backdrop { background: rgba(14, 20, 17, 0.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
#intro { margin: auto; padding: 16px; }

.card {
  position: relative; background: var(--card); border-radius: 24px; padding: 24px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); max-height: calc(100dvh - 32px); overflow-y: auto;
  -webkit-user-select: text; user-select: text;
}
.sheet { border-radius: 24px 24px 0 0; padding-bottom: calc(22px + var(--safe-bottom)); max-height: 86dvh; }

h1 { margin: 0 0 6px; font-size: 30px; line-height: 1.1; letter-spacing: -0.02em; font-family: Georgia, "Iowan Old Style", serif; font-weight: 600; text-wrap: balance; }
h2 { margin: 0 0 2px; font-size: 26px; line-height: 1.15; letter-spacing: -0.01em; font-family: Georgia, "Iowan Old Style", serif; font-weight: 600; padding-right: 40px; }
h3 { margin: 22px 0 8px; font-size: 12.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--card-soft); font-weight: 700; }
.lede { margin: 0 0 14px; font-size: 17px; color: var(--card-soft); text-wrap: pretty; }
.how { margin: 0 0 18px; padding: 0; list-style: none; display: grid; gap: 8px; font-size: 15px; }
.how li { padding-left: 16px; position: relative; }
.how li::before { content: ""; position: absolute; left: 0; top: 0.55em; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.fine { margin: 14px 0 0; font-size: 12.5px; color: var(--card-soft); }

.primary, .row button, .actions button, #place-results button {
  min-height: 48px; border-radius: 14px; padding: 0 16px; font-weight: 650;
}
.primary { width: 100%; background: var(--accent); color: var(--accent-ink); font-size: 17px; }
#place-form { margin-top: 16px; }
#place-form label { display: block; font-size: 13.5px; color: var(--card-soft); margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: #fff; color: var(--card-ink); font: inherit;
  -webkit-user-select: text; user-select: text;
}
.row button, .actions button { background: rgba(38, 48, 42, 0.08); color: var(--card-ink); }
#place-results { display: grid; gap: 6px; margin-top: 8px; }
#place-results button { text-align: left; background: #fff; border: 1.5px solid var(--line); font-weight: 550; }
#place-results p { margin: 4px 0 0; font-size: 14px; color: var(--card-soft); }

.close { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(38, 48, 42, 0.08); }
.where { margin: 0; font-size: 14px; color: var(--card-soft); }
.story { margin: 10px 0 0; font-size: 16px; text-wrap: pretty; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: rgba(38, 48, 42, 0.06); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--card-soft); }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 64px; }
.bars div { background: #4f9fc4; border-radius: 5px 5px 2px 2px; min-height: 3px; }
.bars div.none { background: var(--line); }
.bar-labels { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 4px; font-size: 11px; color: var(--card-soft); text-align: center; }

.visitors { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.visitors li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-radius: 14px; background: rgba(38, 48, 42, 0.06); }
.visitors b { font-size: 15.5px; }
.visitors small { grid-column: 1 / -1; font-size: 13px; color: var(--card-soft); }
.tag { align-self: center; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: rgba(38, 48, 42, 0.1); color: var(--card-soft); white-space: nowrap; }
.tag.here { background: var(--accent); color: #fff; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 22px; }
.actions button { font-size: 14.5px; padding: 0 10px; }
.tip { margin: 18px 0 0; font-size: 13.5px; color: var(--card-soft); }

@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
