:root {
  --ink: #1f2a2e;
  --muted: #61707a;
  --paper: #fbf8f1;
  --line: rgba(31, 42, 46, .14);
  --sea: #3f7f9c;
  --accent: #ffcf3d;
  --green: #2f9e54;
  --red: #d93f44;
  --shadow: 0 6px 24px rgba(16, 32, 40, .18), 0 1px 3px rgba(16, 32, 40, .12);
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--sea);
  color: var(--ink);
  font: 15px/1.4 ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; display: block; }
#map.dragging { cursor: grabbing; }

.card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); }
.hud { position: fixed; z-index: 2; pointer-events: none; }
.hud > * { pointer-events: auto; }

.top-left {
  top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left));
  display: grid; gap: 10px; width: min(340px, calc(100vw - 24px));
}
.brand { padding: 10px 14px; }
.brand h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; line-height: 1.1; }
.brand h1::after { content: ' ●'; color: var(--accent); font-size: 14px; vertical-align: middle; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.forecast { padding: 12px 14px; border: 2px solid #f1b8b9; }
.fc-head { display: flex; gap: 10px; align-items: center; }
.fc-icon { font-size: 28px; line-height: 1; }
.fc-head strong { display: block; font-size: 16px; }
.fc-when { color: var(--red); font-weight: 600; font-size: 13px; }
.forecast p { margin: 8px 0; font-size: 13.5px; }
.switch { display: flex; gap: 8px; align-items: center; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--red); }
.fc-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 0 !important; font-weight: 600; }
.fc-stats .lost { color: var(--red); }
.fc-stats .saved { color: var(--green); }

.top-right { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; gap: 8px; }
.chip {
  border: 0; background: var(--paper); border-radius: 999px; padding: 9px 14px; box-shadow: var(--shadow);
  font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
}
.chip.round { width: 40px; height: 40px; padding: 0; justify-content: center; }
.chip:hover { background: #fff; }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 6px; }

.ticker { position: fixed; z-index: 2; right: 12px; top: 64px; display: grid; gap: 6px; justify-items: end; pointer-events: none; }
.tick {
  background: rgba(251, 248, 241, .92); border-radius: 999px; padding: 5px 12px; font-size: 13px; box-shadow: var(--shadow);
  pointer-events: auto; animation: slide-in .25s ease-out; transition: opacity 1s;
}
.tick.fade { opacity: 0; }

.bottom { left: 50%; transform: translateX(-50%); bottom: max(12px, env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; width: max-content; max-width: calc(100vw - 16px); }
.tools { display: flex; gap: 4px; background: var(--paper); padding: 6px; border-radius: 20px; box-shadow: var(--shadow); }
.tool {
  border: 0; background: transparent; border-radius: 14px; padding: 6px 10px 5px; min-width: 60px;
  display: grid; justify-items: center; gap: 1px; font-size: 12px; font-weight: 600; color: var(--muted);
}
.tool .ico { font-size: 22px; line-height: 28px; height: 28px; }
#flis-ico { width: 22px; height: 22px; margin: 3px 0; border-radius: 5px; border: 2px solid rgba(0, 0, 0, .2); }
.tool:hover { background: rgba(31, 42, 46, .06); }
.tool.on { background: var(--ink); color: #fff; }
.palette { display: grid; grid-template-columns: repeat(8, 28px); gap: 6px; background: var(--paper); padding: 8px; border-radius: 16px; box-shadow: var(--shadow); order: -1; }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 2px solid rgba(0, 0, 0, .15); padding: 0; }
.swatch.on { outline: 3px solid var(--ink); outline-offset: 1px; }
.cooldown { background: rgba(31, 42, 46, .86); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; order: -2; }
.cooldown.ready { background: var(--green); }

.tile-panel {
  position: fixed; z-index: 3; left: max(12px, env(safe-area-inset-left)); bottom: calc(var(--bar-h, 90px) + max(24px, env(safe-area-inset-bottom)));
  width: min(340px, calc(100vw - 24px)); padding: 14px 16px; animation: slide-in .2s ease-out;
}
.tile-panel h2 { margin: 0 28px 6px 0; font-size: 16px; }
.tile-info { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.tile-info li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tile-info q { font-weight: 700; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .2); }
.muted { color: var(--muted); }
.warn { color: var(--red); }
#sign-text { width: 100%; margin-bottom: 8px; }
.tile-extra { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; }
.reason { color: var(--red); font-size: 13px; margin: 6px 0 0; min-height: 0; }
.reason:empty { display: none; }

input { border: 1.5px solid var(--line); border-radius: 12px; padding: 9px 12px; background: #fff; min-width: 0; }
input:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.primary { border: 0; background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 16px; font-weight: 700; }
.primary:disabled { background: #b9c0c3; cursor: not-allowed; }
.primary:not(:disabled):hover { background: #33454b; }
.wide { width: 100%; }
.link { border: 0; background: none; padding: 0; color: var(--sea); font-weight: 600; font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--red); }
.close { position: absolute; top: 8px; right: 8px; border: 0; background: none; font-size: 22px; line-height: 1; padding: 6px 10px; color: var(--muted); }
.coord { border: 0; background: #e6f0f4; color: var(--sea); border-radius: 6px; padding: 0 5px; font-weight: 700; font-size: .95em; }

.drawer {
  position: fixed; z-index: 4; top: 64px; right: max(12px, env(safe-area-inset-right)); bottom: calc(var(--bar-h, 90px) + max(24px, env(safe-area-inset-bottom)));
  width: min(360px, calc(100vw - 24px)); display: flex; flex-direction: column; animation: slide-in .2s ease-out;
}
.drawer-head { position: relative; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-head .close { top: 4px; }
.messages, .annals { list-style: none; margin: 0; padding: 10px 14px; overflow-y: auto; flex: 1; display: grid; align-content: start; gap: 8px; }
.messages li { overflow-wrap: anywhere; }
.messages time { color: var(--muted); font-size: 11px; margin-left: 6px; }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; }
.annals li h3 { margin: 6px 0 2px; font-size: 15px; }
.annals li p { margin: 0; color: var(--muted); font-size: 13.5px; }
.annals li p.event { color: var(--ink); font-weight: 600; margin-top: 4px; }

.timeline { padding: 10px 14px; width: min(720px, calc(100vw - 24px)); justify-items: stretch; }
.tl-row { display: flex; align-items: center; gap: 10px; }
.tl-row.small { font-size: 13px; color: var(--muted); display: grid; }
#tl-range { flex: 1; accent-color: var(--ink); padding: 0; border: 0; }
.tl-marks { position: relative; height: 16px; margin: 0 52px 0 50px; }
.mark { position: absolute; transform: translateX(-50%); font-size: 13px; }
.timeline .chip { box-shadow: none; background: #ece7db; }

dialog { border: 0; border-radius: 20px; padding: 0; max-width: min(460px, calc(100vw - 24px)); box-shadow: var(--shadow); background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgba(16, 32, 40, .35); backdrop-filter: blur(2px); }
dialog form { padding: 22px; display: grid; gap: 10px; }
dialog h2 { margin: 0; font-size: 22px; }
dialog p { margin: 0; }
dialog label { display: grid; gap: 6px; font-weight: 700; margin-top: 6px; }
.rules { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; }
.row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.row button:not(.primary) { border: 0; background: none; color: var(--muted); font-weight: 600; }

.toast {
  position: fixed; z-index: 10; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px); font-weight: 600; animation: drop .25s ease-out;
}
.toast.error { background: var(--red); }
.toast.event { background: #7a2e1f; font-size: 16px; padding: 14px 20px; }

@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } }
@keyframes drop { from { transform: translate(-50%, -10px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (max-width: 700px) {
  .top-left { width: calc(100vw - 24px); gap: 8px; }
  .brand { padding: 8px 12px; margin-right: 144px; }
  .brand h1 { font-size: 20px; }
  .brand p { font-size: 12px; }
  .forecast { padding: 10px 12px; }
  .forecast p#fc-text { display: none; }
  .top-right { gap: 6px; }
  .top-right .chip:not(.round) { width: 40px; height: 40px; padding: 0; justify-content: center; position: relative; font-size: 17px; }
  .top-right .lbl { display: none; }
  .top-right .badge { position: absolute; top: -4px; right: -4px; font-size: 11px; }
  .ticker { display: none; }
  .tools { gap: 0; padding: 4px; }
  .tool { min-width: 0; width: calc((100vw - 32px) / 6); padding: 5px 2px; font-size: 11px; }
  .palette { grid-template-columns: repeat(8, 1fr); width: calc(100vw - 24px); }
  .swatch { width: 100%; height: 30px; }
  .tile-panel { left: 12px; right: 12px; width: auto; }
  .drawer { top: 60px; left: 12px; right: 12px; width: auto; bottom: 12px; z-index: 6; }
  .timeline { bottom: 12px; }
}
