/* WP8a · css/base.css — 基礎 Design Tokens、共用元件、深藍海事玻璃語言、無障礙與教學高亮 */
@import url("screens.css");
@import url("hud.css");

:root {
  --bg: #060b12;
  --panel: rgba(8, 14, 24, 0.74);
  --panel-light: rgba(8, 14, 24, 0.56);
  --panel-solid: rgba(9, 16, 28, 0.92);
  --panel-sub: rgba(14, 24, 38, 0.64);
  --line: rgba(155, 195, 235, 0.20);
  --line-strong: rgba(145, 210, 255, 0.65);
  --text: #e4ecf5;
  --text-bright: #eef5ff;
  --muted: #8ba3bd;
  --accent: #79d2ff;
  --accent-blue: rgba(48, 125, 190, 0.88);
  --teal: #7ad9de;
  --teal-bg: rgba(24, 145, 152, 0.88);
  --gold: #ffc845;
  --good: #4ce0a2;
  --warn: #f7b74c;
  --bad: #ff5d6c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font-scale: 1;
}

body.font-lg {
  --font-scale: 1.15;
}

body.cb-mode {
  --good: #38d9f5;
  --bad: #ff7a38;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Helvetica Neue", sans-serif;
  font-size: calc(14px * var(--font-scale));
  line-height: 1.45;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#canvas-wrap {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#ui-root {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(14px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
}

#ui-root > * {
  pointer-events: auto;
}

#ui-root.sailing {
  overflow: hidden;
  padding: 0;
}

#ui-root.sailing > * {
  pointer-events: none;
}

#overlay-root {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}

.sv-overlay {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  background: rgba(3, 7, 14, 0.68);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  overflow-y: auto;
}

#curtain {
  position: fixed;
  inset: 0;
  background: #04080f;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 40;
}

#curtain.on {
  opacity: 0.62;
}

#boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: radial-gradient(circle at 50% 35%, #0d1c2e 0%, #060b12 75%);
}

#boot h2 {
  font-size: 24px;
  letter-spacing: 0.12em;
  color: var(--text-bright);
}

#boot p {
  font-size: 13px;
  color: var(--muted);
}

#boot.error {
  color: var(--bad);
  padding: 24px;
  text-align: center;
}

#boot .sv-bar {
  width: 220px;
}

/* ---------- Buttons ---------- */
.sv-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(165, 200, 235, 0.24);
  background: rgba(25, 38, 56, 0.72);
  color: var(--text-bright);
  font-family: inherit;
  font-size: calc(14px * var(--font-scale));
  font-weight: 500;
  padding: 9px 14px;
  min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.1s ease, box-shadow 0.16s ease;
  white-space: nowrap;
}

.sv-btn:hover:not(:disabled) {
  background: rgba(48, 76, 110, 0.85);
  border-color: rgba(165, 210, 255, 0.55);
}

.sv-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.sv-btn.primary {
  background: var(--accent-blue);
  border-color: rgba(145, 210, 255, 0.78);
  color: #ffffff;
  box-shadow: 0 0 16px rgba(72, 165, 245, 0.28);
}

.sv-btn.primary:hover:not(:disabled) {
  background: rgba(58, 145, 218, 0.96);
}

.sv-btn.teal {
  background: var(--teal-bg);
  border-color: rgba(125, 235, 235, 0.75);
  color: #ffffff;
}

.sv-btn.danger {
  background: rgba(145, 36, 46, 0.78);
  border-color: rgba(255, 115, 128, 0.55);
}

.sv-btn.small {
  font-size: calc(13px * var(--font-scale));
  padding: 6px 11px;
  min-height: 38px;
  border-radius: 8px;
}

.sv-btn.big {
  min-width: 92px;
  min-height: 48px;
  font-size: calc(14px * var(--font-scale));
  padding: 10px 14px;
}

.sv-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.sv-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---------- Cards, Rows, Bars, Tags ---------- */
.sv-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(11px);
  -webkit-backdrop-filter: blur(11px);
}

body.quality-low .sv-card,
body.quality-medium .sv-card,
body.quality-low .sv-modal,
body.quality-medium .sv-modal,
body.quality-low .sv-portbar,
body.quality-medium .sv-portbar {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: var(--panel-solid);
}

.sv-card h3 {
  font-size: calc(15px * var(--font-scale));
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.sv-rows {
  display: grid;
  grid-template-columns: minmax(76px, auto) 1fr;
  gap: 5px 12px;
  font-size: calc(13px * var(--font-scale));
  align-items: center;
}

.sv-rows dt {
  color: var(--muted);
}

.sv-rows dd {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.sv-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.sv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.sv-bar {
  height: 7px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  overflow: hidden;
  min-width: 68px;
}

.sv-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

.sv-bar.good i { background: var(--good); }
.sv-bar.warn i { background: var(--warn); }
.sv-bar.bad i { background: var(--bad); }
.sv-bar.xp i { background: linear-gradient(90deg, var(--accent), var(--gold)); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: calc(12px * var(--font-scale));
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(76, 224, 162, 0.18);
  border: 1px solid rgba(76, 224, 162, 0.35);
  color: var(--good);
  white-space: nowrap;
}

.tag.warn {
  background: rgba(247, 183, 76, 0.18);
  border-color: rgba(247, 183, 76, 0.42);
  color: var(--warn);
}

.tag.bad {
  background: rgba(255, 93, 108, 0.18);
  border-color: rgba(255, 93, 108, 0.42);
  color: var(--bad);
}

.tag.info {
  background: rgba(121, 210, 255, 0.16);
  border-color: rgba(121, 210, 255, 0.36);
  color: var(--accent);
}

.tag.lock {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--muted);
}

.warn { color: var(--warn); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Modal ---------- */
.sv-modal {
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 18px;
  width: min(560px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.sv-modal.wide {
  width: min(760px, 100%);
}

.sv-modal h2 {
  font-size: calc(18px * var(--font-scale));
  color: var(--text-bright);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sv-modal label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: calc(14px * var(--font-scale));
  padding: 4px 0;
}

.sv-modal select,
.sv-modal input[type="range"] {
  background: rgba(14, 24, 38, 0.9);
  color: var(--text-bright);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  min-height: 36px;
}

.sv-modal input[type="range"] {
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
  width: 140px;
}

.sv-export {
  width: 100%;
  font-size: 12px;
  background: #0a1420;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  -webkit-user-select: text;
  user-select: text;
}

/* ---------- Toast ---------- */
.sv-toasts {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  max-width: calc(100vw - 24px);
}

.sv-toast {
  background: rgba(8, 16, 28, 0.92);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: calc(13px * var(--font-scale));
  color: var(--text-bright);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  transition: opacity 0.45s ease, transform 0.25s ease;
  text-align: center;
}

.sv-toast.good { border-color: var(--good); }
.sv-toast.warn { border-color: var(--warn); }
.sv-toast.error { border-color: var(--bad); }
.sv-toast.out { opacity: 0; transform: translateY(-6px); }

/* ---------- Tutorial Onboarding Banner & Spotlight (WP8b) ---------- */
.sv-tut-banner {
  position: fixed;
  top: calc(70px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  width: min(520px, calc(100vw - 24px));
  background: rgba(8, 22, 38, 0.90);
  border: 1px solid rgba(121, 210, 255, 0.72);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55), 0 0 18px rgba(121, 210, 255, 0.22);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sv-tut-banner.in-port {
  top: auto;
  bottom: calc(14px + env(safe-area-inset-bottom));
}

.sv-tut-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--teal);
  font-weight: 600;
}

.sv-tut-text {
  font-size: calc(14px * var(--font-scale));
  color: var(--text-bright);
  line-height: 1.4;
}

.sv-tut-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.sv-tut-spotlight {
  position: relative;
  box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(121, 210, 255, 0.65) !important;
  animation: svTutPulse 1.4s ease-in-out infinite;
}

@keyframes svTutPulse {
  0%, 100% { box-shadow: 0 0 0 2px #79d2ff, 0 0 12px rgba(121, 210, 255, 0.45); }
  50% { box-shadow: 0 0 0 4px #7ad9de, 0 0 24px rgba(122, 217, 222, 0.85); }
}

/* ---------- Debug ---------- */
#debug-panel {
  position: fixed;
  right: 6px;
  bottom: 6px;
  z-index: 70;
  background: rgba(0, 0, 0, 0.78);
  color: #9fe;
  font: 11px/1.35 ui-monospace, Menlo, monospace;
  padding: 6px 8px;
  border-radius: 6px;
  max-width: 420px;
  max-height: 60vh;
  overflow: auto;
  pointer-events: none;
}

#debug-panel td:first-child {
  color: #8ab;
  padding-right: 8px;
  white-space: nowrap;
  vertical-align: top;
}

@media (max-width: 720px) {
  #ui-root {
    padding: calc(10px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  }
  .sv-grid {
    grid-template-columns: 1fr;
  }
  .sv-tut-banner {
    top: calc(64px + env(safe-area-inset-top));
    padding: 8px 11px;
  }
  .sv-tut-banner.in-port {
    top: calc(8px + env(safe-area-inset-top));
    bottom: auto;
  }
  body.sv-tut-in-port #ui-root {
    padding-top: calc(96px + env(safe-area-inset-top));
  }
}

body.sv-tut-in-port .sv-screen.port,
body.sv-tut-in-port .sv-screen.prep,
body.sv-tut-in-port .sv-screen.results {
  padding-bottom: 120px;
}
