:root {
  --bg: #05070d;
  --ink: #e9f2ff;
  --muted: #8fa4bd;
  --line: rgba(180, 215, 255, 0.16);
  --glass: rgba(9, 17, 30, 0.58);
  --warm: #ffc46b;
  --cyan: #8fd8ff;
  --green: #57d39a;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: absolute; inset: 0; }

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background:
    radial-gradient(120% 80% at 50% 8%, #0b1730 0%, #060a13 48%, #03050a 100%);
  touch-action: none;
  outline: none;
}

/* top bar */
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 14px calc(16px + env(safe-area-inset-left));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, rgba(3, 6, 12, 0.82), rgba(3, 6, 12, 0));
  pointer-events: none;
  z-index: 5;
}

.top-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
  flex: 0 0 auto;
}

.icon-btn.install {
  border-color: rgba(87, 211, 154, 0.45);
  color: #bfffe3;
  box-shadow: 0 0 18px rgba(87, 211, 154, 0.18);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.22em;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.brand p {
  margin: 4px 0 0;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--muted);
  white-space: nowrap;
}

.moon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8f7ff, #8fd8ff 62%, #3f7fb5);
  box-shadow: 0 0 18px rgba(120, 205, 255, 0.55), inset -7px 3px 0 rgba(5, 8, 14, 0.85);
  flex: 0 0 auto;
}

.moon.big { width: 46px; height: 46px; box-shadow: 0 0 34px rgba(120, 205, 255, 0.5), inset -12px 5px 0 rgba(5, 8, 14, 0.88); }

.icon-btn {
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--glass);
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  cursor: pointer;
  flex: 0 0 auto;
}

.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* hint */
.hint {
  position: absolute;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(6, 12, 22, 0.62);
  color: #b9cce2;
  font-size: 11px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  pointer-events: none;
  z-index: 4;
}

.hint.hide { opacity: 0; transform: translate(-50%, 8px); }

/* bottom dock */
.dock {
  position: absolute;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(7, 13, 23, 0.72);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.48);
  z-index: 6;
}

.dock button {
  appearance: none;
  border: 0;
  touch-action: manipulation;
  background: transparent;
  color: #c9d9ec;
  border-radius: 14px;
  min-height: 48px;
  padding: 5px 8px;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, transform 0.12s ease;
}

.dock button:active { transform: scale(0.96); }

.dock button b {
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0.04em;
}

.dock button span {
  font-size: 9px;
  letter-spacing: 0.12em;
  color: #7f93aa;
}

.dock button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dock button.active,
.dock button[aria-pressed="true"] {
  background: linear-gradient(180deg, rgba(80, 160, 160, 0.22), rgba(40, 90, 90, 0.12));
  color: #d9fff1;
  box-shadow: inset 0 0 0 1px rgba(87, 211, 154, 0.3);
}

.dock button.active span,
.dock button[aria-pressed="true"] span { color: #57d39a; }

.dock .divider { display: none; }

/* loading */
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(80% 60% at 50% 38%, rgba(16, 34, 60, 0.92), rgba(4, 7, 13, 0.98) 70%),
    #04070d;
  z-index: 20;
  transition: opacity 0.7s ease, visibility 0.7s ease;
}

.loading.done { opacity: 0; visibility: hidden; }

.loading-inner {
  width: min(300px, 76vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.loading h2 {
  margin: 8px 0 0;
  font-size: 17px;
  letter-spacing: 0.34em;
  font-weight: 800;
}

.loading p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
}

.loading .bar {
  width: 100%;
  height: 3px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(150, 190, 235, 0.14);
  overflow: hidden;
}

.loading .bar i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #57d39a, #8fd8ff);
  box-shadow: 0 0 16px rgba(120, 220, 210, 0.65);
  transition: width 0.25s ease;
}

.loading small { color: #6f849b; font-size: 10px; letter-spacing: 0.12em; }

/* error */
.error {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, 84vw);
  padding: 20px;
  border: 1px solid rgba(255, 120, 120, 0.3);
  border-radius: 18px;
  background: rgba(20, 8, 10, 0.86);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 30;
  font-size: 13px;
  line-height: 1.6;
}

.error strong { display: block; margin-bottom: 6px; color: #ffb4b4; }
.error p { margin: 6px 0; color: #e7c9c9; }
.error code, .about code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.9em;
}

/* about */
.about {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 5, 10, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 15;
}

.about-card {
  position: relative;
  width: min(380px, 100%);
  max-height: 80vh;
  overflow: auto;
  padding: 24px 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(14, 24, 40, 0.96), rgba(7, 12, 22, 0.96));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.about-card h2 { margin: 0; font-size: 18px; letter-spacing: 0.26em; }
.about-card .sub { margin: 6px 0 16px; color: var(--cyan); font-size: 11px; letter-spacing: 0.14em; }
.about-card p { margin: 10px 0; color: #c4d4e6; font-size: 13px; line-height: 1.7; }
.about-card ul { margin: 12px 0; padding-left: 18px; color: #a9bdd3; font-size: 12px; line-height: 1.8; }
.about-card .muted { color: #7f93aa; font-size: 11px; }
.about-card .install-help { color: #a9bdd3; }

.quality-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 14px 0 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.quality-row > span {
  margin: 0 6px 0 4px;
  color: #8fa4bd;
  font-size: 11px;
  letter-spacing: 0.1em;
}

.q-btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #9fb3c9;
  font: inherit;
  font-size: 11px;
  min-height: 36px;
  padding: 0 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.q-btn.active {
  border-color: rgba(87, 211, 154, 0.35);
  background: rgba(87, 211, 154, 0.14);
  color: #bfffe3;
}

.quality-info {
  display: block;
  margin: 2px 4px 10px;
  color: #6f849b;
  font-size: 10px;
  letter-spacing: 0.08em;
}
.about-card .close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; }

@media (max-width: 520px) {
  .top-actions { gap: 6px; }
  .icon-btn { width: 42px; height: 42px; }
  .dock .divider { display: none; }
  .dock { gap: 0; padding: 5px; overflow: hidden; }
  .dock button { padding: 4px 1px; min-width: 0; flex: 1 1 0; }
  .dock button.toggle span { display: none; }
  .dock button.view-btn span { font-size: 8px; letter-spacing: 0.02em; }
  .brand h1 { font-size: 13px; }
  .brand p { font-size: 9px; }
  .moon { width: 23px; height: 23px; }
  .dock { gap: 1px; padding: 5px; border-radius: 18px; }
  .dock button { min-height: 46px; padding: 4px 3px; }
  .dock button span { font-size: 8px; letter-spacing: 0.06em; }
  .dock button b { font-size: 12px; }
  .hint { bottom: calc(90px + env(safe-area-inset-bottom)); font-size: 10px; }
}

@media (max-height: 430px) and (orientation: landscape) {
  .topbar { padding-top: calc(8px + env(safe-area-inset-top)); }
  .brand p { display: none; }
  .about-card { max-height: 88vh; }
  .brand p { display: none; }
  .dock { width: min(600px, calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right))); bottom: calc(6px + env(safe-area-inset-bottom)); }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .loading, .hint, .dock button { transition: none; }
}
