:root {
  --navy: #0E1B2C;
  --navy-2: #132338;
  --navy-3: #1A2D45;
  --line: #2C4058;
  --brass: #D9A441;
  --cream: #EDE6D6;
  --muted: #8FA3B8;
  --danger: #E08A7A;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --serif: "IM Fell English", Georgia, serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy);
  color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; overflow: hidden; }

#app { height: 100%; display: flex; flex-direction: column; max-width: 520px; margin: 0 auto; }

.view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 16px) 18px 18px;
}
.view.voyage { display: flex; flex-direction: column; overflow: hidden; }

.tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--navy);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  flex: 1;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 10px 0 8px;
  font: inherit;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.tabbar button.on { color: var(--brass); }
.tabbar svg { width: 24px; height: 24px; }

.eyebrow { font-size: 13px; color: var(--muted); }
.title { font-size: 27px; font-weight: 600; margin: 2px 0; letter-spacing: -0.01em; }
.sub { font-size: 14px; color: var(--muted); line-height: 1.5; margin: 0; }
.serif { font-family: var(--serif); font-weight: 400; }
.page-title { font-family: var(--serif); font-size: 30px; font-weight: 400; margin: 0 0 16px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.mapwrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; margin: 14px 0; }
.mapwrap canvas { display: block; border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }

.actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--cream);
  border-radius: 14px;
  padding: 16px;
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn.brass { border-color: var(--brass); color: var(--brass); }
.btn.solid { background: var(--brass); border-color: var(--brass); color: #1b1408; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 8px 13px; font-size: 14px; border-radius: 10px; }
.btn.block { display: block; width: 100%; }
.stack { display: grid; gap: 10px; margin-top: 18px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit;
  font-size: 14px;
  background: none;
  color: var(--cream);
  cursor: pointer;
}
.chip.on { border-color: var(--brass); color: var(--brass); background: rgba(217, 164, 65, 0.1); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg .chip { border-radius: 12px; padding: 12px 8px; text-align: center; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale .chip { border-radius: 12px; padding: 12px 0; text-align: center; }
.scale-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

.card { background: var(--navy-2); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.card p { margin: 0 0 10px; }

.field { margin: 18px 0; }
.label, .field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }

input, textarea {
  width: 100%;
  background: var(--navy);
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-size: 16px;
}
input:focus, textarea:focus { outline: none; border-color: var(--brass); }
textarea { min-height: 130px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #5d7087; }
input[type="datetime-local"] { -webkit-appearance: none; min-height: 46px; }

.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 0; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 15, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
  animation: fade 0.2s;
}
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92%;
  overflow-y: auto;
  background: var(--navy-2);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--line);
  padding: 10px 18px calc(var(--safe-b) + 20px);
  animation: up 0.25s ease-out;
}
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 16px; }
.sheet h2 { font-size: 22px; margin: 0 0 6px; font-weight: 600; }
.sheet h2.serif { font-size: 26px; font-weight: 400; }
.sheet ul { padding-left: 20px; margin: 8px 0; line-height: 1.6; }

.full {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 24px);
  overflow-y: auto;
  animation: fade 0.25s;
}
.timer { font-size: 44px; font-weight: 300; font-variant-numeric: tabular-nums; margin: 8px 0 18px; }
.breath {
  width: 170px;
  height: 170px;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid var(--brass);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brass);
  font-size: 15px;
  transform: scale(0.85);
}
.letter { font-family: var(--serif); font-size: 19px; line-height: 1.55; margin: 28px 0 12px; white-space: pre-wrap; max-width: 420px; }
.grow { flex: 1; }

.stepper { display: flex; align-items: center; justify-content: center; gap: 24px; }
.stepper button { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: none; color: var(--cream); font-size: 22px; cursor: pointer; }
.stepper .n { font-size: 40px; font-weight: 300; min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; }

.dots { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.dot { width: 30px; height: 30px; margin: 0 auto; border-radius: 50%; border: 1px solid var(--line); }
.dot.used { background: var(--muted); border-color: var(--muted); }
.dot.clear { border-color: var(--brass); background: rgba(217, 164, 65, 0.15); }
.dot.today { box-shadow: 0 0 0 2px var(--navy-2), 0 0 0 3px var(--cream); }
.dot-label { font-size: 11px; color: var(--muted); margin-top: 5px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.stat { background: var(--navy); border-radius: 12px; padding: 10px 12px; }
.stat .n { font-size: 20px; font-weight: 600; }
.stat .l { font-size: 12px; color: var(--muted); }

.bar-row { display: grid; grid-template-columns: 74px 1fr 52px; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.bar { position: relative; height: 10px; border-radius: 5px; background: var(--navy); }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; background: var(--muted); }
.bar b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--brass); }

.entry { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .what { font-size: 15px; }
.entry .when { font-size: 12px; color: var(--muted); margin-top: 2px; }
.entry .x { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 20px; padding: 4px 8px; cursor: pointer; }
.tag { display: inline-block; font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: 6px; color: var(--muted); }

.rule { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.rule button { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; }
.inline-add { display: flex; gap: 8px; margin-top: 12px; }
.inline-add input { flex: 1; }

.lock-dots { display: flex; gap: 16px; margin: 28px 0 36px; }
.lock-dots span { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--cream); }
.lock-dots span.on { background: var(--cream); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px; }
.keypad button { width: 76px; height: 76px; border-radius: 50%; border: 1px solid var(--line); background: var(--navy-2); color: var(--cream); font-size: 28px; font-weight: 300; cursor: pointer; }
.keypad button.plain { background: none; border: 0; font-size: 15px; color: var(--muted); }
.shake { animation: shake 0.35s; }

.onboard { display: flex; flex-direction: column; min-height: 100%; }
.onboard .brand { font-family: var(--serif); font-size: 52px; margin: 28px 0 8px; }
.onboard ul { padding-left: 20px; line-height: 1.65; color: var(--cream); font-size: 16px; }
.onboard li { margin-bottom: 8px; }
.hint { font-size: 13px; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 12px; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-t) + 12px);
  transform: translate(-50%, -16px);
  opacity: 0;
  background: var(--cream);
  color: #1b1408;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 50;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes up { from { transform: translateY(40px); opacity: 0.5; } }
@keyframes fade { from { opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
