:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #ffffff;
  color: #0f172a;
  --scene-safe-top: 0px;
  --scene-safe-bottom: 0px;
  --mobile-panel-max-height: 44dvh;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #ffffff;
}

button,
input { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: stretch;
  overflow: hidden;
  background: #ffffff;
}

#scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: #ffffff;
}

.phase-panel,
.wind-panel,
.panel {
  z-index: 10;
}

.phase-panel {
  position: fixed;
  left: 18px;
  top: 18px;
  width: min(330px, calc(100vw - 36px));
  height: min(330px, calc(100vw - 36px));
  padding: 12px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.10);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#phase {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#phase:active { cursor: grabbing; }

.wind-panel {
  display: none;
}

.panel {
  position: fixed;
  left: 18px;
  bottom: 18px;
  width: min(390px, calc(100vw - 36px));
  padding: 16px;
  border: 1px solid rgba(37, 99, 235, 0.14);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.11);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #2563eb;
  box-shadow: 0 0 0 7px rgba(37, 99, 235, 0.10);
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #64748b;
}

.panel-primary { display: block; }

.target-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0 10px;
}

.target-button,
.pause-button,
.panel-collapse-toggle {
  appearance: none;
  border: 1px solid #bfdbfe;
  border-radius: 16px;
  color: #1e3a8a;
  background: #ffffff;
  cursor: pointer;
  font-weight: 750;
  line-height: 1.05;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.target-button { padding: 10px 4px 9px; }

.panel-actions { display: block; }

.pause-button {
  width: 100%;
  margin: 0 0 4px;
  padding: 10px 12px;
  color: #ffffff;
  border-color: #2563eb;
  background: linear-gradient(90deg, #1d4ed8, #38bdf8);
  box-shadow: 0 10px 28px rgba(37, 99, 235, 0.20);
}

.panel-collapse-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: fit-content;
  margin: 0.45rem auto 0;
  padding: 0.36rem 0.72rem;
  color: #334155;
  border-color: rgba(37, 99, 235, 0.18);
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.055);
  font-size: 0.75rem;
  line-height: 1;
  opacity: 0.86;
}

.target-button:hover,
.pause-button:hover,
.panel-collapse-toggle:hover { transform: translateY(-1px); }

.target-button:active,
.pause-button:active,
.panel-collapse-toggle:active { transform: translateY(0); }

.target-button.active {
  color: #ffffff;
  border-color: #2563eb;
  background: #2563eb;
  box-shadow: 0 10px 26px rgba(37, 99, 235, 0.18);
}

.target-button span {
  display: inline-block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  opacity: 0.80;
}

.panel-collapse-toggle:focus-visible,
.target-button:focus-visible,
.pause-button:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.panel-collapse-icon {
  display: inline-block;
  font-size: 0.9rem;
  transition: transform 180ms ease;
}

.panel-collapse-toggle[aria-expanded="true"] .panel-collapse-icon {
  transform: rotate(180deg);
}

.advanced-controls[hidden] { display: none !important; }

.slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  margin-top: 12px;
  align-items: center;
  color: #334155;
  font-size: 12px;
}

.slider-row output {
  color: #0f172a;
  font-variant-numeric: tabular-nums;
}

.slider-row input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: #2563eb;
}

.readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
}

.readout div {
  min-width: 0;
  padding: 9px 10px;
  border-radius: 14px;
  background: rgba(37, 99, 235, 0.055);
}

.readout div:last-child { grid-column: 1 / -1; }

.readout dt {
  margin: 0 0 2px;
  color: #64748b;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.readout dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  html,
  body,
  .app-shell {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
  }

  #scene {
    inset: var(--scene-safe-top, 150px) 0 var(--scene-safe-bottom, 108px);
    width: 100vw;
    height: auto;
    min-height: 160px;
  }

  .phase-panel {
    left: max(8px, env(safe-area-inset-left));
    top: max(8px, env(safe-area-inset-top));
    width: clamp(116px, 31vw, 148px);
    height: auto;
    aspect-ratio: 1;
    padding: 6px;
    border-radius: 16px;
    box-shadow: 0 12px 35px rgba(15, 23, 42, 0.10);
  }

  .wind-panel {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    left: calc(max(8px, env(safe-area-inset-left)) + clamp(116px, 31vw, 148px) + 8px);
    right: max(8px, env(safe-area-inset-right));
    display: flex;
    min-width: 0;
    min-height: 54px;
    padding: 9px 12px;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid rgba(37, 99, 235, 0.14);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 12px 35px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    pointer-events: none;
  }

  .wind-label {
    display: flex;
    flex-direction: column;
    min-width: 0;
    color: #64748b;
    font-size: 9px;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: 0.10em;
    text-transform: uppercase;
  }

  .wind-label strong {
    margin-top: 3px;
    overflow: hidden;
    color: #0f172a;
    font-size: 12px;
    line-height: 1.1;
    letter-spacing: 0;
    text-transform: none;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .wind-icon {
    display: grid;
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 999px;
    color: #2563eb;
    background: rgba(37, 99, 235, 0.09);
    font-size: 17px;
  }

  .panel {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
    max-height: var(--mobile-panel-max-height, 44dvh);
    padding: 8px;
    overflow: hidden;
    border-radius: 17px;
    box-shadow: 0 14px 42px rgba(15, 23, 42, 0.12);
  }

  .brand,
  .readout { display: none; }

  .panel-primary {
    display: grid;
    gap: 6px;
  }

  .target-grid {
    gap: 6px;
    margin: 0;
  }

  .target-button {
    min-width: 0;
    min-height: 42px;
    padding: 6px 2px 5px;
    border-radius: 12px;
    font-size: 13px;
    touch-action: manipulation;
  }

  .target-button span {
    margin-top: 2px;
    font-size: 9px;
  }

  .panel-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
  }

  .pause-button,
  .panel-collapse-toggle {
    min-height: 38px;
    margin: 0;
    padding: 7px 12px;
    border-radius: 12px;
    touch-action: manipulation;
  }

  .panel-collapse-toggle {
    width: auto;
    min-width: 94px;
    opacity: 1;
  }

  .advanced-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    max-height: max(48px, calc(var(--mobile-panel-max-height, 44dvh) - 102px));
    margin-top: 7px;
    padding: 1px 1px 3px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .slider-row {
    min-width: 0;
    margin: 0;
    padding: 7px 8px 5px;
    gap: 3px 5px;
    border-radius: 12px;
    background: rgba(37, 99, 235, 0.055);
    font-size: 10px;
    line-height: 1.15;
  }

  .slider-row span,
  .slider-row output {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .slider-row output {
    max-width: 88px;
    font-size: 10px;
  }

  .slider-row input {
    min-height: 25px;
    margin: 0;
    touch-action: pan-x;
  }
}

@media (max-width: 370px) {
  .phase-panel {
    width: 110px;
  }

  .wind-panel {
    left: calc(max(8px, env(safe-area-inset-left)) + 118px);
    padding-inline: 9px;
  }

  .wind-icon { display: none; }

  .panel-collapse-toggle {
    min-width: 80px;
    padding-inline: 8px;
  }

  .slider-row output { max-width: 70px; }
}

@media (max-width: 920px) and (orientation: landscape) {
  .phase-panel {
    width: clamp(92px, 20vh, 112px);
  }

  .wind-panel {
    left: calc(max(8px, env(safe-area-inset-left)) + clamp(92px, 20vh, 112px) + 8px);
    min-height: 46px;
    padding-block: 6px;
  }

  .panel-primary {
    grid-template-columns: minmax(0, 1fr) minmax(175px, 0.48fr);
    align-items: center;
  }

  .target-button { min-height: 36px; }

  .pause-button,
  .panel-collapse-toggle { min-height: 36px; }

  .advanced-controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-height: max(42px, calc(var(--mobile-panel-max-height, 44dvh) - 54px));
  }
}

@media (max-height: 620px) and (max-width: 720px) {
  #scene { min-height: 130px; }

  .phase-panel { width: clamp(96px, 25vw, 116px); }

  .wind-panel {
    left: calc(max(8px, env(safe-area-inset-left)) + clamp(96px, 25vw, 116px) + 8px);
    min-height: 46px;
  }

  .target-button { min-height: 36px; }
}

@media (min-width: 721px) and (max-height: 620px) {
  .panel {
    max-height: calc(100vh - 20px);
    overflow: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
