/* style.css — washi paper, sumi ink and vermillion: the control surface is
   part of the piece, so it is built from the same palette as the village. */

:root {
  --paper: #f0e8d8;
  --paper-2: #e2d8c2;
  --ink: #241f1a;
  --ink-soft: #4a4038;
  --vermillion: #b5442e;
  --indigo: #2f4a72;
  --wood: #8a6844;
  --moss: #5c7a3e;
  --shadow: 0 6px 22px rgba(10, 8, 6, 0.45);
  --radius: 10px;
  --ui-font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "Songti SC", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #070a12;
  color: var(--ink);
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app, #viewport { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#ui > * { pointer-events: auto; }

/* ------------------------------------------------------------------ */
/* Loading veil                                                        */
/* ------------------------------------------------------------------ */

.veil {
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 120% at 50% 30%, #14203a 0%, #070a12 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  transition: opacity 1.1s ease, visibility 1.1s ease;
  text-align: center;
  color: var(--paper);
}
.veil.gone { opacity: 0; visibility: hidden; }
.veil-inner { max-width: min(560px, 88vw); padding: 24px; }
.veil-kicker { font-size: 12px; letter-spacing: 0.34em; text-transform: uppercase; opacity: 0.62; margin-bottom: 14px; }
.veil-title { font-family: var(--serif); font-size: clamp(38px, 7vw, 62px); margin: 0 0 10px; font-weight: 600; letter-spacing: 0.06em; }
.veil-sub { font-size: 15px; line-height: 1.6; opacity: 0.78; margin: 0 auto 26px; max-width: 44ch; }
.bar { width: min(340px, 70vw); height: 4px; margin: 0 auto 8px; background: rgba(240, 232, 216, 0.18); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--vermillion), #e8a24a); transition: width 0.25s ease; }
.loading-pct { font-size: 11px; letter-spacing: 0.22em; opacity: 0.55; margin-bottom: 26px; font-variant-numeric: tabular-nums; }
.enter-btn {
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0.12em;
  color: var(--paper);
  background: linear-gradient(180deg, #b5442e, #8f3324);
  border: 1px solid rgba(255, 220, 190, 0.28);
  border-radius: 999px;
  padding: 13px 34px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, opacity 0.3s ease, box-shadow 0.2s ease;
}
.enter-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5); }
.enter-btn:disabled { opacity: 0.35; cursor: default; }
.veil.ready .enter-btn { animation: pulse 2.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 6px 22px rgba(10, 8, 6, 0.45); } 50% { box-shadow: 0 6px 30px rgba(181, 68, 46, 0.55); } }
.veil-hint { margin-top: 18px; font-size: 11px; letter-spacing: 0.16em; opacity: 0.5; }

/* ------------------------------------------------------------------ */
/* Brand + clock                                                       */
/* ------------------------------------------------------------------ */

.brand {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--paper);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  opacity: 0.85;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  background: var(--vermillion);
  color: var(--paper);
  border-radius: 4px;
  font-family: var(--serif);
  font-size: 15px;
  box-shadow: var(--shadow);
}
.brand-name { font-family: var(--serif); letter-spacing: 0.18em; font-size: 14px; }

.clock {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  width: 292px;
  padding: 12px 14px 10px;
  background: linear-gradient(180deg, rgba(242, 236, 222, 0.96), rgba(226, 216, 194, 0.94));
  border: 1px solid rgba(60, 48, 34, 0.35);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(3px);
}
.clock::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(90, 70, 48, 0.22);
  border-radius: 7px;
  pointer-events: none;
}
.clock-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.clock-time { font-family: var(--serif); font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.clock-phase { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-soft); margin-top: 4px; }
.clock-seal {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border: 1.5px solid var(--vermillion);
  color: var(--vermillion);
  border-radius: 5px;
  font-family: var(--serif);
  font-size: 15px;
  transform: rotate(-2deg);
}
.clock-buttons { display: flex; gap: 6px; margin: 10px 0 8px; }
.btn {
  font-size: 13px;
  min-width: 44px; height: 30px;
  border-radius: 6px;
  border: 1px solid rgba(60, 48, 34, 0.4);
  background: rgba(255, 252, 244, 0.75);
  color: var(--ink);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.btn:hover { background: #fffdf6; }
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-bottom: 8px; }
.preset {
  font-size: 10.5px;
  letter-spacing: 0.04em;
  padding: 6px 2px;
  min-height: 30px;
  border-radius: 5px;
  border: 1px solid rgba(60, 48, 34, 0.32);
  background: rgba(255, 252, 244, 0.6);
  color: var(--ink-soft);
  cursor: pointer;
}
.preset:hover { background: var(--indigo); color: var(--paper); border-color: var(--indigo); }
.scrub-wrap { padding-top: 2px; }
.scrub {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
.scrub::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, #1b2540 0%, #6a7bb0 22%, #d8e8f4 46%, #ffb070 62%, #ff8040 72%, #4a4a78 80%, #101a30 100%);
}
.scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px; height: 17px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--vermillion);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.scrub::-moz-range-track { height: 5px; border-radius: 3px; background: linear-gradient(90deg, #1b2540, #d8e8f4 46%, #ff8040 72%, #101a30); }
.scrub::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--paper); border: 2px solid var(--vermillion); }
.scrub-ticks { display: flex; justify-content: space-between; font-size: 9px; letter-spacing: 0.12em; color: var(--ink-soft); opacity: 0.7; }

/* ------------------------------------------------------------------ */
/* Legend, caption, crosshair                                          */
/* ------------------------------------------------------------------ */

.legend {
  position: fixed;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  padding: 10px 12px;
  background: rgba(240, 232, 216, 0.92);
  border: 1px solid rgba(60, 48, 34, 0.3);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 260px;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.legend.collapsed { opacity: 0; transform: translateY(8px); pointer-events: none; }
.legend-row { display: flex; gap: 8px; font-size: 11.5px; line-height: 1.7; }
.legend-key { min-width: 68px; color: var(--vermillion); font-weight: 600; }
.legend-val { color: var(--ink-soft); }
.legend-toggle {
  position: fixed;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(60, 48, 34, 0.35);
  background: rgba(240, 232, 216, 0.92);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: -1;
}
.legend.collapsed ~ .legend-toggle, .legend-toggle { z-index: auto; }

.caption {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  padding: 7px 14px;
  background: rgba(36, 31, 26, 0.78);
  color: var(--paper);
  border-radius: 999px;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: min(86vw, 460px);
  text-align: center;
  font-family: var(--serif);
}
.caption.visible { opacity: 1; transform: translate(-50%, 0); }

.crosshair {
  position: fixed;
  left: 50%; top: 50%;
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  display: grid; place-items: center;
  opacity: 0.55;
}
.crosshair .dot {
  width: 4px; height: 4px;
  background: var(--paper);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.mode-chip {
  position: fixed;
  left: 50%;
  top: calc(18px + env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 5px 12px;
  font-size: 11px;
  letter-spacing: 0.14em;
  background: rgba(36, 31, 26, 0.7);
  color: var(--paper);
  border-radius: 999px;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* Touch controls                                                      */
/* ------------------------------------------------------------------ */

.stick, .lookzone { display: none; }
body.touch .stick {
  display: block;
  position: fixed;
  left: calc(20px + env(safe-area-inset-left));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 124px; height: 124px;
  border-radius: 50%;
  background: rgba(36, 31, 26, 0.42);
  border: 2px solid rgba(240, 232, 216, 0.6);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  touch-action: none;
}
body.touch .stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 48px; height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(240, 232, 216, 0.82);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
body.touch .lookzone {
  display: block;
  position: fixed;
  right: 0; top: 0;
  width: 58%;
  height: 100%;
  touch-action: none;
  z-index: -1;
}
body.touch .legend { display: none; }
body.touch .crosshair { opacity: 0.35; }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 760px) {
  .clock {
    left: calc(10px + env(safe-area-inset-left));
    right: calc(10px + env(safe-area-inset-right));
    width: auto;
    padding: 9px 11px 7px;
  }
  .clock-time { font-size: 26px; }
  .presets { grid-template-columns: repeat(4, 1fr); }
  .preset { min-height: 40px; font-size: 10px; }
  .btn { min-width: 48px; height: 40px; font-size: 15px; }
  .brand { top: auto; bottom: calc(154px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); }
  .brand-name { display: none; }
  .caption { bottom: calc(196px + env(safe-area-inset-bottom)); font-size: 12px; }
  .legend { display: none; }
  .legend-toggle { display: none; }
  .scrub-ticks { font-size: 8px; }
}

@media (max-height: 560px) {
  .veil-sub { display: none; }
  .presets { grid-template-columns: repeat(8, 1fr); }
  .preset { min-height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  .veil, .caption, .enter-btn { transition-duration: 0.01s; animation: none; }
}
