:root {
  --ink-mono: -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--ink-mono);
  transition: background 0.4s ease, color 0.4s ease;
}

/* ---------- Theme: Circa (faithful monochrome recreation) ---------- */
body.theme-circa {
  background: #ffffff;
  color: #1a1a1a;
  --night: #000000;
  --astro: #2b2b2b;
  --nautical: #595959;
  --civil: #b0b0b0;
  --day: #ffffff;
  --ink: #1a1a1a;
  --ink-soft: #9a9a9a;
  --accent: #1a1a1a;
  --hand-mode: plain; /* hand can dim into night, faithful to the original */
}

/* ---------- Theme: Clear (structured, legible, hour numbers) ---------- */
body.theme-clear {
  background: #ffffff;
  color: #1a1a1a;
  --night: #000000;
  --astro: #2b2b2b;
  --nautical: #595959;
  --civil: #b0b0b0;
  --day: #ffffff;
  --ink: #1a1a1a;
  --ink-soft: #9a9a9a;
  --accent: #1a1a1a;
  --hand-mode: diff; /* always legible */
}

/* ---------- Theme: Poetic (atmospheric amber/dusk) ---------- */
body.theme-poetic {
  background: #05060a;
  color: #E9E4D6;
  --night: #0A0D14;
  --astro: #4A3B5C;
  --nautical: #8a6a4f;
  --civil: #C98B4A;
  --day: #F2EDE1;
  --ink: #E9E4D6;
  --ink-soft: rgba(233,228,214,0.55);
  --accent: #C9A66B;
  --hand-mode: diff;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 22px 0 26px;
}

#wordmark {
  font-size: 13px;
  font-style: italic;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

#theme-switch {
  display: flex;
  gap: 2px;
  background: rgba(128,128,128,0.12);
  border-radius: 20px;
  padding: 3px;
}
.theme-btn {
  border: none;
  background: none;
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 5px 12px;
  border-radius: 16px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--ink-mono);
}
.theme-btn.active {
  background: var(--accent);
  color: #ffffff;
}
body.theme-poetic .theme-btn.active { color: #1A1710; }

#face-region {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#face-wrap {
  position: relative;
  width: min(72vw, 56vh, 460px);
  height: min(72vw, 56vh, 460px);
}

#face {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: relative;
  transition: background 1.2s ease;
  box-shadow: 0 0 0 1.5px rgba(128,128,128,0.25);
}

#hand {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2.4px;
  height: 42%;
  transform-origin: 50% 0%;
  margin-left: -1.2px;
  pointer-events: none;
}
/* plain mode: solid ink color, can visually recede into a matching-color night wedge */
body:not([data-hand="diff"]) #hand,
body:not([data-hand="diff"]) #hand-tip,
body:not([data-hand="diff"]) #pivot {
  background: var(--ink);
}
/* diff mode: mix-blend-mode guarantees contrast on both day and night */
body[data-hand="diff"] #hand,
body[data-hand="diff"] #hand-tip,
body[data-hand="diff"] #pivot {
  background: #ffffff;
  mix-blend-mode: difference;
}

#hand-tip {
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  border-radius: 50%;
}

#pivot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
}

.tick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1px;
  height: 50%;
  transform-origin: 50% 0%;
  margin-left: -0.5px;
}
.tick::after {
  content: '';
  position: absolute;
  top: 2%;
  left: 0;
  width: 1px;
  height: 1.4%;
  background: rgba(128,128,128,0.3);
}
.tick.major::after {
  top: 1.4%;
  height: 2.4%;
  width: 1.3px;
  background: rgba(128,128,128,0.55);
}

#hour-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
}
body.theme-clear #hour-labels,
body.theme-poetic #hour-labels {
  display: block;
}
#hour-labels span {
  position: absolute;
  font-size: 12px;
  font-weight: 500;
  color: #ffffff;
  opacity: 0.6;
  mix-blend-mode: difference;
  transform: translate(-50%, -50%);
}
body.theme-poetic #hour-labels span {
  font-family: Georgia, serif;
  font-style: italic;
  font-weight: 400;
}

#exact-time {
  position: absolute;
  left: 50%;
  top: 66%;
  transform: translate(-50%, -50%) scale(0.9);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.04em;
  background: rgba(0,0,0,0.78);
  color: #ffffff;
  padding: 5px 11px;
  border-radius: 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
}
#exact-time.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#credit {
  text-align: center;
  font-size: 10.5px;
  color: var(--ink-soft);
  padding: 0 20px;
  flex-shrink: 0;
}
#credit a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}

#footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px 26px 24px;
}

#share-btn, #info-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#share-btn svg, #info-btn svg { width: 18px; height: 18px; }
#info-btn {
  border: 1.4px solid var(--ink-soft);
  border-radius: 50%;
}

#place-line {
  font-size: 13px;
  color: var(--ink);
  letter-spacing: 0.01em;
}

#panel {
  position: absolute;
  bottom: 78px;
  right: 20px;
  background: rgba(20,20,20,0.95);
  border-radius: 12px;
  padding: 16px;
  display: none;
  width: 230px;
  color: rgba(255,255,255,0.9);
  font-size: 11px;
  letter-spacing: 0.03em;
  box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  z-index: 10;
}
#panel.open { display: block; }
#panel label { display: block; margin-top: 10px; opacity: 0.75; }
#panel input {
  width: 100%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 12px;
  margin-top: 3px;
}
#panel button:not(.ghost-btn) {
  margin-top: 12px;
  width: 100%;
  padding: 7px;
  background: #fff;
  color: #000;
  border: none;
  border-radius: 5px;
  font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.ghost-btn {
  margin-top: 6px;
  width: 100%;
  padding: 7px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 5px;
  font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer;
}
#panel .geo-note {
  margin-top: 10px;
  opacity: 0.55;
  font-size: 10px;
  line-height: 1.4;
}
