:root {
  --bg: #070a16;
  --fg: #eef2ff;
  --mut: #9aa3c7;
  --a1: #7c5cff;
  --a2: #00e0c6;
  --card: rgba(255, 255, 255, .06);
  --bd: rgba(255, 255, 255, .12);
  --work: #3dd68c;
  --shoulder: #f0b429;
  --sleep: #7d86ad;
  --danger: #ff6b8a;
  --shadow: 0 20px 60px rgba(0, 0, 0, .28);
  --digit: #bff6ee;
  --ok: #8af0c0;
  color-scheme: dark;
}
body.light {
  --bg: #eef1fb;
  --fg: #141833;
  --mut: #5a6390;
  --card: rgba(255, 255, 255, .62);
  --bd: rgba(20, 24, 51, .12);
  --digit: #3b2fb0;
  --ok: #0d7a48;
  --shadow: 0 16px 40px rgba(40, 50, 90, .12);
  color-scheme: light;
}
body.face-minimal {
  --a1: #5c6b86;
  --a2: #1f6feb;
  --digit: var(--fg);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.lang-th {
  font-family: "Noto Sans Thai", "Thonburi", "Sukhumvit Set", "Leelawadee UI", system-ui, sans-serif;
}
body.lang-th .place { letter-spacing: .08em; }
#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.bar, nav, main, .amb-hint, .install, #toast, #alarm-overlay { position: relative; z-index: 1; }
.bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 12px;
  padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 8px calc(16px + env(safe-area-inset-left));
}
.brand {
  font-weight: 800;
  letter-spacing: .35em;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--a1), var(--a2));
  box-shadow: 0 0 14px var(--a2);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.45); opacity: .65; } }
.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; }
.actions button, .face-pick select, #close, #help-close, .btnrow button, .inline-form button,
.planner-actions button, .shift-actions button, .alarm-form button, .presets button, .install button,
.alarm-box button, .days button {
  background: var(--card);
  border: 1px solid var(--bd);
  color: var(--fg);
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 700;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform .2s, border-color .2s, background .2s;
}
.actions button:hover, .face-pick select:hover, .shift-actions button:hover, .btnrow button:hover,
.presets button:hover, .planner-actions button:hover { transform: translateY(-2px); border-color: var(--a2); }
button:disabled { opacity: .45; cursor: default; transform: none !important; }
.face-pick select { padding: 8px 10px; max-width: 118px; }
button.primary, #best-btn, #timer-go, #sw-start, #pomo-go, #install-go {
  background: linear-gradient(135deg, rgba(124, 92, 255, .85), rgba(0, 224, 198, .75));
  color: #04120f;
  border-color: transparent;
}
body.light button.primary, body.light #best-btn, body.light #timer-go, body.light #sw-start,
body.light #pomo-go, body.light #install-go { color: #fff; }
[hidden] { display: none !important; }
.tabs {
  position: sticky;
  top: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 0 auto;
  max-width: 1300px;
  padding: 8px calc(16px + env(safe-area-inset-right)) 8px calc(16px + env(safe-area-inset-left));
  background: rgba(7, 10, 22, .78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
body.light .tabs { background: rgba(238, 241, 251, .82); }
.tabs button {
  background: transparent;
  color: var(--mut);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 6px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.tabs button.on { color: var(--fg); border-color: var(--bd); background: var(--card); }
main {
  padding: 8px calc(16px + env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  max-width: 1300px;
  margin: auto;
}
.glass {
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 24px;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow);
}
.hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  padding: 28px 32px;
  flex-wrap: wrap;
  transition: transform .35s ease;
}
#analog { width: min(280px, 62vw); filter: drop-shadow(0 0 28px rgba(124, 92, 255, .35)); }
.face { fill: rgba(255, 255, 255, .03); stroke: url(#g); stroke-width: 2; }
.tick { stroke: var(--mut); stroke-width: 1; }
.tick.big { stroke: var(--fg); stroke-width: 3; }
.hand { stroke-linecap: round; }
.h { stroke: var(--fg); stroke-width: 6; }
.m { stroke: var(--fg); stroke-width: 4; }
.s { stroke: var(--a2); stroke-width: 2; }
.digital { text-align: center; min-width: min(100%, 320px); }
.place { color: var(--mut); letter-spacing: .28em; text-transform: uppercase; font-size: 13px; font-weight: 650; }
.digits {
  display: flex;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-weight: 200;
  font-size: clamp(52px, 10vw, 120px);
  line-height: 1;
  margin: 6px 0;
  color: var(--fg);
}
.d span, .d.sep { color: var(--digit); text-shadow: 0 0 24px rgba(0, 224, 198, .35); }
body.light .d span, body.light .d.sep, body.face-minimal .d span, body.face-minimal .d.sep { text-shadow: none; }
.d { display: inline-block; height: 1em; overflow: hidden; position: relative; width: .62em; text-align: center; }
.d span { display: block; transition: transform .45s cubic-bezier(.2, .8, .2, 1); }
.d.sep { width: .28em; animation: blink 1s steps(2) infinite; }
.d.sm { font-size: .42em; width: .62em; align-self: flex-end; margin-bottom: .18em; }
.ampm { font-size: .22em; align-self: flex-start; margin: .35em 0 0 .25em; color: var(--a2); font-weight: 700; letter-spacing: .08em; }
@keyframes blink { 50% { opacity: .35; } }
.meta-row { display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap; color: var(--mut); }
.date { font-size: 17px; }
.moon { font-size: 14px; }
.sunline { margin-top: 8px; color: var(--mut); font-size: 14px; min-height: 1.2em; }
.flipclock { display: none; gap: 6px; align-items: center; justify-content: center; margin: 8px 0 4px; }
.flap {
  position: relative;
  width: .78em;
  height: 1.18em;
  font-size: clamp(58px, 11vw, 112px);
  border-radius: 12px;
  background: linear-gradient(#32384d, #161a28);
  color: #f5f7ff;
  box-shadow: 0 12px 24px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .18);
  overflow: hidden;
}
.flap b { display: grid; place-items: center; height: 100%; font-weight: 650; font-variant-numeric: tabular-nums; }
.flap .line { position: absolute; left: 0; right: 0; top: 50%; height: 2px; background: rgba(0, 0, 0, .55); pointer-events: none; }
.flap.play { animation: flap .42s ease; }
@keyframes flap { from { transform: rotateX(88deg); filter: brightness(.65); } to { transform: rotateX(0); } }
.colon { font-size: clamp(42px, 8vw, 84px); color: var(--a2); width: .32em; text-align: center; font-weight: 300; text-shadow: 0 0 16px rgba(0, 224, 198, .45); }
.flip-side { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-left: 8px; color: var(--mut); font-variant-numeric: tabular-nums; }
.flip-side .sec { font-size: 28px; color: var(--digit); }
.flip-side .ap { letter-spacing: .14em; font-weight: 800; color: var(--a2); font-size: 14px; }
body.face-flip .flipclock { display: flex; }
body.face-flip #digits, body.face-flip #analog { display: none; }
body.face-analog #digits, body.face-analog .flipclock { display: none; }
body.face-analog #analog { width: min(460px, 86vw); }
body.face-analog .hero { flex-direction: column; gap: 12px; }
body.face-analog .date { font-size: 22px; }
body.face-minimal #bg { opacity: .45; }
body.face-minimal .dot { animation: none; box-shadow: none; }
body.face-flip .hero { background: rgba(6, 8, 16, .45); }
.shift { margin-top: 16px; padding: 14px 16px 12px; }
.shift-top, .shift-actions, .planner-actions, .btnrow, .inline-form, .legend, .phases {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.shift-top { justify-content: space-between; }
#shift-readout { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
#plan-date, input[type="time"], input[type="number"], input[type="text"], input[type="search"], select, #q {
  background: rgba(0, 0, 0, .22);
  color: var(--fg);
  border: 1px solid var(--bd);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
}
body.light #plan-date, body.light input, body.light select, body.light #q { background: rgba(255, 255, 255, .72); }
#slider { width: 100%; margin: 12px 0 0; accent-color: var(--a2); height: 28px; }
.shift-scale { display: flex; justify-content: space-between; color: var(--mut); font-size: 11px; font-variant-numeric: tabular-nums; padding: 0 2px; }
.travel, .moment, .map-note, .hint, .note, .sub, .hint-keys { color: var(--mut); font-size: 13px; }
.travel { margin: 8px 0 0; color: var(--shoulder); }
.moment { margin: 4px 0 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 16px; }
.city { padding: 16px 16px 14px; position: relative; transition: transform .25s, border-color .25s; animation: in .45s both; }
.city:hover { transform: translateY(-3px); }
.city.in-work { border-color: rgba(61, 214, 140, .55); }
.city.shoulder { border-color: rgba(240, 180, 41, .5); }
.city.asleep { border-color: rgba(125, 134, 173, .35); }
.city.dragging { opacity: .6; outline: 2px dashed var(--a2); }
@keyframes in { from { opacity: 0; transform: translateY(14px); } }
.city-top { display: flex; align-items: center; gap: 6px; }
.city h3 { margin: 0; font-size: 16px; font-weight: 650; flex: 1; min-width: 0; }
.city h3 .nm { overflow-wrap: anywhere; }
.city .t { font-size: 36px; font-weight: 300; font-variant-numeric: tabular-nums; margin: 8px 0 2px; letter-spacing: -.02em; }
.city .m, .city .sun, .city .row-chip { color: var(--mut); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.city .sun { margin-top: 4px; }
.grip, .city .x {
  background: none; border: 0; color: var(--mut); cursor: pointer; font-size: 16px; padding: 4px;
}
.grip { cursor: grab; touch-action: none; letter-spacing: -2px; font-size: 14px; }
.city .x { opacity: 0; transition: opacity .2s; }
.city:hover .x, .city:focus-within .x { opacity: 1; }
@media (hover: none) { .city .x, .grip { opacity: .75; } }
.chip { font-size: 11px; font-weight: 700; letter-spacing: .02em; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.chip.work { background: rgba(61, 214, 140, .16); color: var(--ok); }
.chip.shoulder { background: rgba(240, 180, 41, .16); color: var(--shoulder); }
.chip.sleep { background: rgba(125, 134, 173, .16); color: var(--mut); }
.rel { font-size: 12px; }
.bar24 { position: relative; height: 6px; border-radius: 6px; background: rgba(128, 128, 128, .28); margin-top: 10px; }
.bar24 .work { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, #2f9e6b, var(--work)); border-radius: 6px; }
.bar24 .now { position: absolute; top: -3px; width: 2px; height: 12px; background: #fff; border-radius: 2px; box-shadow: 0 0 8px var(--a2); }
body.light .bar24 .now { background: #141833; }
.empty { padding: 28px; text-align: center; margin-top: 16px; }
.legend { margin: 16px 0 10px; }
.sw { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.sw.work, .cell.work { background: var(--work); }
.sw.shoulder, .cell.shoulder { background: var(--shoulder); }
.sw.sleep, .cell.sleep { background: #2a3148; }
body.light .cell.sleep { background: #c5cbe0; }
.best { padding: 16px 18px; margin-bottom: 12px; }
.best .kicker, .alarm-box .kicker { margin: 0; color: var(--mut); letter-spacing: .14em; text-transform: uppercase; font-size: 11px; font-weight: 800; }
.best-time { margin: 6px 0 0; font-size: clamp(26px, 4vw, 40px); font-weight: 300; font-variant-numeric: tabular-nums; }
.best p { margin: 6px 0 0; }
.lane { margin: 10px 0; }
.lane-h { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.lane-h strong { font-size: 15px; }
.lane-h .lt { font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 650; }
.lane-h label { color: var(--mut); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.lane-h input[type="time"] { padding: 4px 6px; font-size: 14px; }
.track { position: relative; height: 22px; border-radius: 8px; overflow: hidden; background: rgba(0, 0, 0, .2); cursor: pointer; }
.cells { display: grid; grid-template-columns: repeat(48, 1fr); height: 100%; }
.cell { min-width: 0; }
.needle { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 10px var(--a2); pointer-events: none; }
body.light .needle { background: #141833; }
.lane.overlap .track { height: 14px; }
.planner-actions { margin: 12px 0 4px; }
.map-wrap { position: relative; height: 340px; padding: 0; overflow: hidden; }
#map { width: 100%; height: 100%; display: block; cursor: crosshair; }
.map-wrap::after {
  content: "";
  position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, .35);
}
.map-tip {
  position: absolute; z-index: 2; pointer-events: none;
  background: rgba(8, 10, 20, .88); color: #fff; border-radius: 12px;
  padding: 8px 10px; font-size: 13px; max-width: 220px;
  transform: translate(-50%, -120%);
}
.map-note { margin: 10px 4px 0; }
.tools { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 16px; }
.tool { padding: 16px 16px 14px; }
.tool h2 { margin: 0 0 8px; font-size: 16px; letter-spacing: .04em; }
.readout { font-size: clamp(40px, 8vw, 64px); font-weight: 250; font-variant-numeric: tabular-nums; letter-spacing: -.03em; text-align: center; }
.ring-wrap { position: relative; width: min(220px, 70vw); margin: 0 auto 8px; }
.ring { width: 100%; height: auto; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(128, 128, 128, .25); stroke-width: 8; }
.ring-fg { fill: none; stroke: url(#g); stroke: var(--a2); stroke-width: 8; stroke-linecap: round; }
.ring-read { position: absolute; inset: 0; display: grid; place-items: center; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }
.presets button { padding: 8px 10px; }
.phases button.on { border-color: var(--a2); color: var(--fg); }
.laps, .alarm-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 220px; overflow: auto; }
.laps li, .alarm-list li {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  padding: 8px 2px; border-top: 1px solid var(--bd); font-variant-numeric: tabular-nums;
}
.alarm-form { display: grid; grid-template-columns: 1fr; gap: 8px; }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.days button { min-width: 40px; padding: 8px; }
.days button.on { background: rgba(0, 224, 198, .2); border-color: var(--a2); }
.alarm-list button { background: none; border: 0; color: var(--mut); cursor: pointer; font: inherit; }
.alarms { grid-column: 1 / -1; }
.hint-keys { text-align: center; margin: 22px 0 0; }
.amb-hint {
  position: fixed; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom));
  text-align: center; z-index: 15; color: var(--mut); letter-spacing: .08em;
  transition: opacity 1.2s ease;
}
.amb-hint.fade { opacity: 0; }
body.ambient header, body.ambient nav, body.ambient #shift, body.ambient #panel-clocks,
body.ambient #panel-planner, body.ambient #panel-map, body.ambient #panel-tools,
body.ambient .hint-keys, body.ambient .install { display: none !important; }
body.ambient main { min-height: 100dvh; display: grid; place-items: center; padding: 0; max-width: none; }
body.ambient .hero {
  width: min(1100px, 100%);
  min-height: 100dvh;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}
body.ambient .digits { font-size: clamp(72px, 16vw, 210px); }
body.ambient .flap { font-size: clamp(72px, 16vw, 200px); }
body.ambient #analog { width: min(520px, 70vw); }
body.ambient .sunline, body.ambient .moon, body.ambient .date { display: none; }
body.ambient .digital { padding-bottom: 28px; }
.install {
  position: relative; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center;
  margin: 0 auto 8px;
  width: min(1300px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: 16px;
}
#toast {
  position: fixed; z-index: 40; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  background: rgba(10, 14, 28, .92); color: #fff;
  padding: 10px 16px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: .25s ease; max-width: min(92vw, 420px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.alarm-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(4, 6, 16, .55);
  backdrop-filter: blur(8px);
  padding: 20px;
}
.alarm-overlay[hidden] { display: none; }
.alarm-box { padding: 28px 24px; text-align: center; width: min(420px, 100%); animation: in .35s both; }
.alarm-box h2 { margin: 8px 0; font-size: 36px; font-weight: 300; font-variant-numeric: tabular-nums; }
dialog {
  color: var(--fg);
  width: min(520px, 94vw);
  padding: 16px;
  border: 1px solid var(--bd);
  background: rgba(12, 16, 32, .94);
}
body.light dialog { background: rgba(244, 246, 252, .97); }
dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 10px; font-size: 18px; }
#q { width: 100%; }
#list { list-style: none; padding: 0; margin: 10px 0; max-height: min(50vh, 420px); overflow: auto; }
#list li {
  padding: 10px; border-radius: 10px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
#list li small { color: var(--mut); }
#list li:hover, #list li.hi { background: rgba(255, 255, 255, .06); }
body.light #list li:hover, body.light #list li.hi { background: rgba(20, 24, 51, .06); }
#list li.have { opacity: .45; }
#help-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 12px; }
#help-list dt { font-weight: 800; color: var(--a2); }
#help-list dd { margin: 0; }
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--a2); outline-offset: 2px; }
@media (min-width: 900px) {
  .tools { grid-template-columns: 1fr 1fr; }
  .map-wrap { height: 500px; }
  .alarm-form { grid-template-columns: 140px 1fr 1fr auto; align-items: center; }
  .alarm-form .days { grid-column: 1 / -1; }
}
body.compact .hero { padding: 12px 18px; gap: 18px; }
body.compact #analog { width: 108px; filter: none; }
body.compact .digits { font-size: 52px; margin: 0; }
body.compact .place { font-size: 11px; }
body.compact .date, body.compact .moon, body.compact .sunline { display: none; }
body.compact .flap { font-size: 46px; }
body.compact .colon { font-size: 32px; }
body.compact .flip-side .sec { font-size: 16px; }
@media (max-width: 720px) {
  .bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .actions { width: 100%; justify-content: flex-start; gap: 4px; }
  .actions button, .face-pick select { padding: 7px 8px; font-size: 13px; }
  .face-pick select { max-width: 86px; }
  .hero { gap: 4px; padding: 14px 12px; }
  #analog { width: min(200px, 54vw); }
  .digits { font-size: clamp(46px, 14vw, 68px); }
  .city .t { font-size: 32px; }
  .actions button, .face-pick select { padding: 8px 10px; }
  .face-pick select { max-width: 108px; }
  #shift-readout { width: 100%; }
  .hint-keys { display: none; }
  .install { width: auto; margin: 0 12px 8px; }
  body.compact #analog { width: 72px; }
  body.compact .digits { font-size: 34px; }
  body.compact .hero { padding: 8px 12px; }
  .map-wrap { height: 420px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
