:root {
  color-scheme: dark;
  --ink: #effcff;
  --muted: #9db3bd;
  --cyan: #42f4db;
  --blue: #5ab8ff;
  --red: #ff4f5f;
  --panel: rgba(8, 16, 24, 0.74);
  --panel-strong: rgba(9, 21, 32, 0.94);
  --line: rgba(126, 242, 229, 0.25);
  --gold: #ffd36a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  font-family: "Avenir Next", "Noto Sans TC", "PingFang TC", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #020509;
  color: var(--ink);
  touch-action: none;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app,
#space {
  position: fixed;
  inset: 0;
}

#space {
  width: 100vw;
  height: 100dvh;
  cursor: grab;
}

#space:active {
  cursor: grabbing;
}

.hud {
  position: fixed;
  z-index: 5;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  pointer-events: none;
}

.top-hud {
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  justify-content: space-between;
}

.hud-pill,
.system-panel,
.design-toolbar,
dialog {
  border: 1px solid rgba(122, 236, 224, 0.22);
  background: linear-gradient(145deg, rgba(10, 24, 36, 0.92), rgba(5, 10, 17, 0.72));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.hud-pill {
  min-height: 44px;
  border-radius: 8px;
  padding: 9px 12px;
  pointer-events: auto;
}

button.hud-pill {
  border: 1px solid rgba(122, 236, 224, 0.22);
}

.wide {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  min-width: 174px;
  background: rgba(5, 18, 27, 0.76);
}

.temp-pill {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  min-width: 220px;
  cursor: pointer;
}

.temp-pill small {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.temp-pill strong {
  font-size: 20px;
  color: var(--gold);
  text-align: right;
}

.habitability-badge {
  grid-column: 1 / -1;
  color: #ff263d;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0;
  text-align: right;
  text-shadow: 0 0 12px rgba(255, 38, 61, 0.55);
}

.mini-button,
.ghost-button,
.primary-button,
.danger-button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  padding: 8px 11px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.mini-button {
  grid-column: 1 / -1;
  padding: 5px 8px;
  color: var(--cyan);
}

.primary-button {
  border-color: rgba(66, 244, 219, 0.42);
  background: linear-gradient(135deg, rgba(30, 166, 151, 0.95), rgba(41, 105, 190, 0.92));
  font-weight: 700;
}

.danger-button {
  border-color: rgba(255, 79, 95, 0.48);
  background: rgba(255, 79, 95, 0.16);
  color: #ffd1d5;
}

.system-panel {
  position: fixed;
  z-index: 6;
  top: calc(max(12px, env(safe-area-inset-top)) + 58px);
  left: 12px;
  width: min(560px, calc(100vw - 24px));
  border-radius: 8px;
  padding: 14px;
  transition: transform 180ms ease, opacity 180ms ease;
}

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

.summary-card {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.055);
}

.summary-card small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-card strong {
  display: block;
  margin-top: 4px;
  color: #fff;
}

.design-toolbar {
  position: fixed;
  z-index: 7;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(680px, calc(100vw - 24px));
  padding: 9px;
  border-radius: 8px;
  transform: translateX(-50%);
}

.add-button {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(66, 244, 219, 0.5);
  border-radius: 50%;
  background: rgba(66, 244, 219, 0.14);
  color: var(--cyan);
  font-size: 30px;
  line-height: 1;
}

.mode-title {
  min-width: 0;
  flex: 1;
}

.mode-title strong,
.mode-title small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-title small {
  color: var(--muted);
  font-size: 12px;
}

.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(-8px);
}

.design-toolbar.hidden {
  transform: translate(-50%, -8px);
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  max-width: min(520px, calc(100vw - 30px));
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(2, 8, 13, 0.86);
  color: #fff;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
}

dialog form {
  padding: 16px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head small {
  color: var(--cyan);
  letter-spacing: 0.12em;
}

.dialog-head h2 {
  margin: 2px 0 0;
  font-size: 24px;
}

.icon-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  font-size: 26px;
}

.field,
.field span {
  display: grid;
  gap: 6px;
}

.field {
  margin-top: 12px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.34);
  color: var(--ink);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 10px;
}

.dial-wrap {
  display: grid;
  grid-template-columns: 138px 1fr;
  gap: 16px;
  align-items: end;
  margin-top: 14px;
}

.angle-dial {
  position: relative;
  width: 128px;
  height: 128px;
  border: 1px solid rgba(66, 244, 219, 0.34);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(66, 244, 219, 0.18) 0 4px, transparent 5px),
    conic-gradient(from 0deg, rgba(66, 244, 219, 0.06), rgba(255, 255, 255, 0.12), rgba(66, 244, 219, 0.06));
  cursor: crosshair;
}

.angle-needle {
  position: absolute;
  top: 62px;
  left: 64px;
  width: 52px;
  height: 3px;
  border-radius: 9px;
  background: var(--red);
  box-shadow: 0 0 14px rgba(255, 79, 95, 0.75);
  transform-origin: 0 50%;
}

.dialog-actions {
  margin: 18px 0 0;
  padding: 0;
}

.history-dialog {
  width: min(760px, calc(100vw - 24px));
}

#historyCanvas {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 14px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.24);
}

.habitability {
  margin: 12px 0 0;
  color: var(--ink);
  line-height: 1.45;
}

@media (max-width: 680px) {
  .top-hud {
    align-items: flex-start;
  }

  .wide {
    min-width: 52px;
    width: 52px;
    height: 44px;
    padding: 9px;
  }

  .wide span {
    display: none;
  }

  .temp-pill {
    min-width: 0;
    width: min(240px, calc(100vw - 82px));
  }

  .design-toolbar {
    align-items: stretch;
  }

  .mode-title {
    display: none;
  }

  .field-grid,
  .summary-grid,
  .dial-wrap {
    grid-template-columns: 1fr;
  }
}
