:root {
  color: #1c2430;
  background: #f3eee4;
  font-family: "PingFang HK", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 18px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
body { background: #d7efe8; -webkit-touch-callout: none; }
button, input { font: inherit; }
button { cursor: pointer; }
p { margin: 0; }

:focus-visible {
  outline: 3px solid #ffbf47;
  outline-offset: 3px;
}

#turn-landscape {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #14324a;
  color: white;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

.turn-card h1 { margin: 12px 0 8px; font-size: 2rem; }
.phone-icon {
  width: 86px;
  height: 54px;
  margin: 0 auto;
  border: 4px solid white;
  border-radius: 8px;
  position: relative;
}
.phone-icon::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 4px;
  border-radius: 4px;
  background: white;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
}

.camera-feed {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #1d2836;
  z-index: 0;
}

body.is-preview .camera-feed { visibility: hidden; }
body.is-preview { background: #243246; }

#app {
  position: relative;
  z-index: 1;
  height: 100%;
}

.screen { height: 100%; }

@supports (height: 100dvh) {
  html, body, #app, .screen { height: 100dvh; }
}

.screen-title,
.screen-loading {
  display: flex;
  background: #f6f1e7;
  text-align: center;
  padding: 24px;
}
.screen-title {
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: calc(36px + env(safe-area-inset-bottom));
}
.screen-loading {
  align-items: center;
  justify-content: center;
}
.title-block {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.title-block h1,
.load-block h1 { margin-bottom: 8px; }
.start-prompt {
  display: block;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: #0f5c62;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 0.12em;
}
.load-block { width: min(560px, 92vw); }
.load-bar {
  height: 22px;
  margin: 22px auto 8px;
  border-radius: 999px;
  background: #e4d8c8;
  overflow: hidden;
}
.load-fill {
  width: 0;
  height: 100%;
  background: #0f5c62;
}
.load-percent {
  font-size: 1.8rem;
  font-weight: 800;
  color: #0f5c62;
}
.load-block .btn { width: auto; min-width: 180px; margin-top: 16px; }

.screen-home {
  position: relative;
  display: grid;
  grid-template-columns: minmax(280px, 1.1fr) minmax(280px, 0.9fr);
  grid-template-rows: auto 1fr;
  gap: 28px;
  padding: calc(20px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(24px + env(safe-area-inset-left));
  background: #f6f1e7;
  overflow: auto;
}
.home-top {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}
.home-top .btn { width: auto; margin-top: 0; }
.intro { align-self: center; }

.eyebrow {
  margin: 0 0 4px;
  color: #0f5c62;
  font-weight: 700;
}

h1 { margin: 0 0 12px; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.15; }

.steps {
  margin: 0 0 16px;
  padding-left: 1.3rem;
  font-size: 1.2rem;
}
.steps li { margin: 8px 0; }
.steps li::marker { font-weight: 700; color: #0f5c62; }

.quiet { color: #3d4a5c; font-size: 0.98rem; margin-top: 8px; }
.note, .error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
}
.note { background: #fff6df; color: #5c4314; }
.error { background: #fde8e4; color: #8a2b1f; }

.cards { display: flex; flex-direction: column; gap: 16px; justify-content: center; }
.card {
  background: white;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
}
.card h2 { margin: 0 0 8px; font-size: 1.8rem; }
.card p { font-size: 1.15rem; }
.card-soon {
  background: transparent;
  border: 2px dashed #b7aa96;
  box-shadow: none;
  color: #5c5348;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 12px 18px;
  border-radius: 14px;
  border: 2px solid transparent;
  font-weight: 700;
}
.btn.primary { background: #0f5c62; color: white; width: 100%; margin-top: 16px; font-size: 1.45rem; min-height: 72px; }
.btn.secondary { background: white; color: #14324a; border-color: #c9d4de; }
.btn.ghost { background: transparent; color: #14324a; width: 100%; }
.btn.small { min-height: 48px; width: auto; margin-top: 0; font-size: 1.05rem; padding: 8px 14px; }
.btn:disabled { opacity: 0.7; }

.screen-settings {
  background: #f6f1e7;
  overflow: auto;
  padding: calc(16px + env(safe-area-inset-top)) 20px 24px;
}
.settings-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.settings-head .btn { width: auto; margin-top: 0; }
.reach-launch {
  margin: 8px 0 18px;
  padding: 16px 16px 8px;
  border-radius: 16px;
  background: white;
}
.reach-launch h2 { margin: 0 0 8px; font-size: 1.45rem; }
.reach-launch p { font-size: 1.05rem; }
.reach-launch .btn { width: auto; min-width: 240px; }

.screen-reach {
  position: relative;
  height: 100%;
  background: transparent;
  touch-action: none;
}
.reach-hud {
  position: absolute;
  z-index: 2;
  top: calc(8px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(20, 32, 44, 0.72);
  color: white;
}
.reach-hud .meters { flex: 1 1 280px; }
.reach-hud .bar { background: rgba(255, 255, 255, 0.28); }
.reach-hint { flex: 1 1 220px; font-size: 1.05rem; }
.reach-actions { display: flex; gap: 8px; }
#reach-stage,
.reach-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.reach-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
fieldset {
  border: 0;
  margin: 0 0 8px;
  padding: 0;
}
legend { font-weight: 700; margin-bottom: 8px; }
fieldset label {
  display: inline-flex;
  position: relative;
  align-items: center;
  min-height: 52px;
  margin: 0 8px 8px 0;
  padding: 0 16px;
  border: 2px solid #c9d4de;
  border-radius: 12px;
  background: white;
}
fieldset input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}
fieldset label:has(input:checked) {
  background: #0f5c62;
  color: white;
  border-color: #0f5c62;
}

.screen-play { position: relative; background: transparent; touch-action: none; }

.preview-banner {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 10px 8px 14px;
  border-radius: 12px;
  background: #fff6df;
  color: #5c4314;
}

.hud {
  position: absolute;
  z-index: 5;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(12, 24, 36, 0.82);
  color: white;
}
body.is-preview .hud { top: calc(62px + env(safe-area-inset-top)); }

.hud-title-wrap { flex: 0 0 auto; }
.hud-title { margin: 0; font-size: 1.35rem; font-weight: 800; white-space: nowrap; }
.hud-timer { margin: 0; font-variant-numeric: tabular-nums; font-size: 1.1rem; }

.meters { flex: 1; display: flex; gap: 12px; min-width: 0; }
.meter { flex: 1; display: grid; grid-template-columns: 3rem 1fr; gap: 8px; align-items: center; font-weight: 700; min-width: 0; }
.bar {
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.38);
  overflow: hidden;
}
.fill { height: 100%; width: 0; background: #8ee0c2; }

.chips { display: flex; gap: 8px; flex: 0 0 auto; }
.chip {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.75);
  font-weight: 700;
}
.chip.on { background: #e7f7f1; color: #0d3b34; }

.hud-hint {
  position: absolute;
  z-index: 5;
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(12, 24, 36, 0.82);
  color: white;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
}

#activity-root { position: absolute; inset: 0; touch-action: none; user-select: none; }
.fly-stage { position: absolute; inset: 0; }
.fly-canvas { width: 100%; height: 100%; display: block; }

.wipe-layout {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(92px + env(safe-area-inset-top)) 18px calc(72px + env(safe-area-inset-bottom));
}
body.is-preview .wipe-layout { padding-top: calc(138px + env(safe-area-inset-top)); }

.window-frame {
  position: relative;
  width: min(92vw, 1200px);
  aspect-ratio: 16 / 9;
  background: #10202c;
  overflow: hidden;
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.28),
    0 0 0 100vmax rgba(6, 10, 16, 0.45);
}
body.is-preview .window-frame { cursor: grab; }

.wipe-view, .wipe-cursor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.wipe-cursor { pointer-events: none; }

.midline {
  position: absolute;
  top: 5%;
  bottom: 5%;
  left: 50%;
  border-left: 4px dashed rgba(255, 255, 255, 0.95);
  transform: translateX(-2px);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

.pane-label {
  position: absolute;
  top: 10px;
  margin: 0;
  color: white;
  font-weight: 800;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}
.pane-label.left { left: 12px; }
.pane-label.right { right: 12px; }

.wipe-alert, .countdown {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.wipe-alert {
  bottom: 16px;
  max-width: 80%;
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(92, 58, 12, 0.92);
  color: white;
  font-weight: 800;
  text-align: center;
}
.countdown {
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  background: rgba(8, 16, 24, 0.28);
  color: white;
  font-size: clamp(4rem, 12vw, 8rem);
  font-weight: 800;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.modal {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 14, 22, 0.55);
}
.modal-card {
  width: min(460px, 100%);
  padding: 24px 22px 18px;
  border-radius: 22px;
  background: #fffaf3;
  text-align: center;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
}
.modal-card h2 { margin: 0 0 8px; font-size: 2.1rem; }
.modal-card p { font-size: 1.25rem; }
.modal-time { margin: 10px 0 4px; font-size: 1.7rem !important; font-weight: 800; color: #0f5c62; }
.modal-card .quiet { font-size: 0.95rem; }
.pause-hands {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.hand-choice {
  min-height: 52px;
  padding: 8px 6px;
  border: 2px solid #c9d4de;
  border-radius: 12px;
  background: white;
  color: #14324a;
  font-weight: 700;
}
.hand-choice.on {
  background: #0f5c62;
  color: white;
  border-color: #0f5c62;
}

@media (orientation: portrait) {
  #app, .camera-feed { display: none !important; }
  #turn-landscape { display: flex; }
}

@media (max-width: 860px) and (orientation: landscape) {
  .screen-home { grid-template-columns: 1fr 1fr; gap: 16px; padding: 12px; }
  h1 { font-size: 1.7rem; }
  .steps { font-size: 1rem; }
  .card h2 { font-size: 1.4rem; }
  .btn.primary { min-height: 60px; font-size: 1.2rem; }
  .hud-title { font-size: 1.1rem; }
  .chip { padding: 4px 8px; }
}

@media (max-height: 430px) and (orientation: landscape) {
  .screen-home { gap: 8px; padding: 8px 12px; }
  .card { padding: 12px; }
  .card h2 { margin-bottom: 4px; font-size: 1.25rem; }
  .btn.primary { min-height: 48px; margin-top: 8px; font-size: 1.1rem; }
  .hud, .reach-hud { padding: 6px 8px; gap: 8px; }
  .hud-hint { font-size: 1rem; padding: 6px 10px; }
  .modal-card h2 { font-size: 1.6rem; }
  .modal-card p { font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
