:root {
  color-scheme: dark;
  --bg: #06210a;
  --panel: #0b3d0b;
  --panel-border: #1f6b2b;
  --text: #ffffff;
  --accent: #ffd400;
  --danger: #ff5252;
  --ok: #2ee65e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

/* display:flex等を明示指定した要素でもhidden属性を確実に優先させる */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}

main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.app-header h1 {
  font-size: clamp(20px, 6vw, 26px);
  text-align: center;
  margin: 0 0 12px;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
}

.view.is-active {
  display: flex;
}

.view-title {
  font-size: clamp(18px, 5vw, 22px);
  margin: 0;
  border-bottom: 2px solid var(--panel-border);
  padding-bottom: 6px;
}

.instruction {
  font-size: clamp(16px, 4.5vw, 19px);
  line-height: 1.5;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preset-btn {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  color: var(--text);
  font-size: clamp(16px, 4.5vw, 19px);
  font-weight: bold;
  padding: 14px 8px;
  border-radius: 12px;
  line-height: 1.3;
}

.preset-btn span {
  font-weight: normal;
  font-size: 0.8em;
  opacity: 0.85;
}

.preset-btn.is-selected {
  border-color: var(--accent);
  background: #16531a;
}

.preset-btn--wide {
  grid-column: 1 / -1;
}

.input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.input-row label {
  font-size: clamp(17px, 4.8vw, 20px);
  flex: 1;
}

.input-row input {
  flex: 1;
  font-size: clamp(20px, 6vw, 26px);
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid var(--panel-border);
  background: #ffffff;
  color: #06210a;
  text-align: right;
  min-width: 0;
  max-width: 140px;
}

.result-box {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 14px;
}

.result-line {
  font-size: clamp(18px, 5vw, 22px);
  margin: 0 0 8px;
}

.btn-primary,
.btn-secondary {
  font-size: clamp(18px, 5vw, 22px);
  font-weight: bold;
  border-radius: 14px;
  padding: 16px;
  border: none;
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #06210a;
}

.btn-primary:disabled {
  opacity: 0.4;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--panel-border);
}

.btn-large {
  padding: 20px;
}

.error-text {
  color: var(--danger);
  font-size: clamp(15px, 4.2vw, 18px);
  font-weight: bold;
}

.heading-readout {
  text-align: center;
  font-size: clamp(40px, 15vw, 64px);
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.target-tabs,
.radius-tabs,
.side-tabs {
  display: flex;
  gap: 8px;
}

.target-tab,
.radius-tab,
.side-tab {
  flex: 1;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  color: var(--text);
  font-size: clamp(15px, 4.2vw, 18px);
  font-weight: bold;
  padding: 10px 4px;
  border-radius: 10px;
}

.target-tab.is-selected,
.radius-tab.is-selected,
.side-tab.is-selected {
  border-color: var(--accent);
  background: #16531a;
}

.stature-suggestions {
  display: flex;
  gap: 8px;
}

.suggestion-btn {
  flex: 1;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  color: var(--text);
  font-size: clamp(13px, 3.6vw, 15px);
  font-weight: bold;
  padding: 10px 6px;
  border-radius: 10px;
  line-height: 1.4;
}

.suggestion-btn span {
  display: block;
  font-size: 1.3em;
  color: var(--accent);
  margin-top: 2px;
}

.diagram-container {
  display: flex;
  justify-content: center;
}

.court-diagram {
  width: min(58vw, 220px);
  height: auto;
  aspect-ratio: 1 / 1;
  display: block;
}

.diagram-container--small .court-diagram {
  width: min(38vw, 140px);
}

.diagram-rect {
  fill: rgba(255, 212, 0, 0.08);
  stroke: var(--panel-border);
  stroke-width: 3;
}

.diagram-dot {
  fill: var(--panel-border);
}

.diagram-dot-a {
  fill: var(--text);
}

.diagram-dot.is-active {
  fill: var(--accent);
}

.diagram-person {
  fill: var(--accent);
}

.diagram-label {
  fill: var(--text);
  font-size: 16px;
  font-weight: bold;
}

.diagram-label.is-active {
  fill: var(--accent);
}

.range-finder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(6, 33, 10, 0.55);
  border-radius: 12px;
  padding: 8px 14px;
}

.range-distance {
  font-size: clamp(40px, 14vw, 60px);
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.range-hint {
  text-align: center;
  font-size: clamp(16px, 4.8vw, 20px);
  font-weight: bold;
  min-height: 2.2em;
  margin: 0;
}

.range-finder.is-on-target .range-distance,
.range-finder.is-on-target .range-hint {
  color: var(--ok);
}

/* 誘導画面: カメラ映像を全画面背景として表示し、UIはその上に半透明パネルで重ねる */
.camera-video {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: -1;
}

.view.has-camera .camera-video {
  display: block;
}

.guide-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.view.has-camera .guide-content {
  background: rgba(6, 33, 10, 0.6);
  border-radius: 16px;
  padding: 14px;
  backdrop-filter: blur(1px);
}

/* レンジファインダーの照準表示 */
.finder-viewport {
  position: relative;
  flex: 1;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  pointer-events: none;
}

.crosshair::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.crosshair-line {
  position: absolute;
  background: var(--accent);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.7);
}

.crosshair-h {
  top: 50%;
  left: 0;
  width: 100%;
  height: 3px;
  transform: translateY(-50%);
}

.crosshair-v {
  top: 0;
  left: 50%;
  width: 3px;
  height: 100%;
  transform: translateX(-50%);
}

.finder-viewport .range-finder {
  position: absolute;
  top: calc(50% + 44px);
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 320px;
}

.compass-display {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.direction-arrow {
  width: min(60vw, 260px);
  height: min(60vw, 260px);
}

.arrow-ring {
  fill: none;
  stroke: var(--panel-border);
  stroke-width: 4;
}

#arrow-group {
  transition: transform 0.15s ease-out;
  transform-origin: 100px 100px;
}

.arrow-shape {
  fill: var(--accent);
  transition: fill 0.2s ease;
}

.arrow-center {
  fill: var(--text);
}

.compass-display.is-on-target .arrow-shape {
  fill: var(--ok);
}

.deviation-deg {
  font-size: clamp(28px, 9vw, 40px);
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.compass-display.is-on-target .deviation-deg {
  color: var(--ok);
}

.guide-message {
  text-align: center;
  font-size: clamp(20px, 6vw, 28px);
  font-weight: bold;
  min-height: 2.6em;
}

.guide-message.is-on-target {
  color: var(--ok);
}

.distance-hint {
  text-align: center;
  font-size: clamp(16px, 4.5vw, 19px);
  opacity: 0.9;
}
