:root {
  color-scheme: dark;
  --bg: #0b0e12;
  --panel: #14191f;
  --panel-2: #1d242b;
  --line: #33404a;
  --text: #eef4f8;
  --muted: #9badb8;
  --accent: #39d6b5;
  --amber: #ffcb5a;
  --alert: #ff5d73;
  --rain: #4ab3ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.map-panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #07090c;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 82px;
  padding: 16px 22px;
  border-bottom: 1px solid #202a31;
  background: rgba(10, 14, 18, 0.94);
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(57, 214, 181, 0.75);
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 48%, rgba(57, 214, 181, 0.55) 50%, transparent 52%),
    linear-gradient(0deg, transparent 48%, rgba(57, 214, 181, 0.55) 50%, transparent 52%),
    radial-gradient(circle, rgba(57, 214, 181, 0.24), transparent 68%);
  box-shadow: 0 0 18px rgba(57, 214, 181, 0.22);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
  font-weight: 760;
  letter-spacing: 0;
}

.brand p,
.status-strip,
.map-label {
  color: var(--muted);
  font-size: 12px;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-strip span {
  min-height: 32px;
  padding: 7px 9px;
  border: 1px solid #2b3842;
  border-radius: 8px;
  background: #11171d;
}

.status-strip b {
  color: var(--text);
  font-weight: 760;
}

.status-strip .live-source {
  display: grid;
  gap: 2px;
  min-width: 250px;
}

.live-source b {
  color: var(--accent);
}

.live-source small {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.15;
}

.viewport {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
}

#cloudCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #06080a;
}

.radar-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.3;
  background:
    linear-gradient(rgba(255, 255, 255, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 80px 80px;
  mix-blend-mode: screen;
}

.map-label {
  position: absolute;
  z-index: 2;
  padding: 3px 7px;
  border: 1px solid rgba(210, 230, 238, 0.18);
  border-radius: 6px;
  background: rgba(8, 12, 15, 0.46);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.danmaku-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}

.danmaku {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  max-width: min(520px, 68vw);
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: #fff;
  background: rgba(9, 13, 17, 0.68);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.72);
  will-change: transform;
}

.danmaku.alert {
  border-color: rgba(255, 93, 115, 0.62);
  color: #ffe8ed;
}

.danmaku .tag {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
}

.danmaku.alert .tag {
  color: var(--alert);
}

.danmaku .text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px 18px 10px;
  border-top: 1px solid #202a31;
  background: rgba(10, 14, 18, 0.95);
}

.icon-button,
.quick-tags button,
form button {
  border: 1px solid #374650;
  color: var(--text);
  background: #172029;
  cursor: pointer;
}

.icon-button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.time-ticks {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  margin-top: -9px;
  color: var(--muted);
  font-size: 10px;
}

.composer {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.primary-composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(190px, 260px) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 82px;
  border-width: 1px 0 0;
  border-right: 0;
  border-left: 0;
  border-radius: 0;
  background: rgba(18, 24, 30, 0.96);
}

.primary-composer h2 {
  margin-bottom: 0;
  white-space: nowrap;
}

.primary-composer .quick-tags {
  margin-bottom: 0;
}

.primary-composer form {
  grid-template-columns: minmax(96px, 140px) minmax(0, 1fr) 64px;
}

.primary-composer #userCodeInput {
  grid-column: auto;
}

.primary-composer .composer-guard {
  grid-column: 3;
  margin-top: -4px;
}

.quick-tags {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.quick-tags button {
  height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  color: var(--muted);
}

form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 8px;
}

#userCodeInput {
  grid-column: 1 / -1;
}

form input {
  width: 100%;
  height: 40px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid #3a4751;
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background: #111820;
}

form input:focus {
  border-color: var(--accent);
}

form button {
  height: 40px;
  border-radius: 8px;
  font-weight: 760;
}

form button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.composer-guard {
  margin-top: 8px;
  color: #7f939f;
  font-size: 11px;
  line-height: 1.4;
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    padding: 10px 12px;
  }

  .map-panel {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .primary-composer {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .primary-composer .quick-tags,
  .primary-composer form,
  .primary-composer .composer-guard {
    grid-column: 1;
  }

  .primary-composer form {
    grid-template-columns: minmax(0, 1fr) 64px;
  }

  .primary-composer #userCodeInput {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  }

  .brand {
    gap: 8px;
    min-width: 0;
    width: 100%;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }

  h1 {
    font-size: 17px;
  }

  .brand p {
    max-width: 100%;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .status-strip {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 6px;
    width: 100%;
    font-size: 10px;
  }

  .status-strip span {
    min-height: 0;
    padding: 5px 6px;
    border-radius: 7px;
  }

  .status-strip .live-source {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .live-source small {
    font-size: 9px;
  }

  .viewport {
    flex: 1 1 0;
    min-height: 220px;
  }

  .map-label {
    padding: 2px 5px;
    font-size: 10px;
  }

  .danmaku {
    height: 29px;
    max-width: 86vw;
    gap: 5px;
    padding: 4px 8px;
    font-size: 13px;
  }

  .danmaku .tag {
    font-size: 10px;
  }

  .timeline {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
    padding: 5px 10px 7px;
  }

  .icon-button {
    width: 28px;
    height: 28px;
    border-radius: 7px;
  }

  .time-ticks {
    margin-top: -7px;
    font-size: 9px;
  }

  .primary-composer {
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .primary-composer h2 {
    display: none;
  }

  .quick-tags {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .quick-tags button {
    height: 28px;
    padding: 0 6px;
    font-size: 12px;
  }

  .primary-composer form {
    grid-template-columns: minmax(74px, 0.38fr) minmax(0, 1fr) 54px;
    gap: 6px;
  }

  .primary-composer #userCodeInput {
    grid-column: auto;
  }

  form input,
  form button {
    height: 36px;
    border-radius: 7px;
    font-size: 13px;
  }

  form input {
    padding: 0 8px;
  }

  .primary-composer .composer-guard {
    grid-column: 1;
    margin-top: -2px;
    font-size: 10px;
    line-height: 1.2;
  }
}

@media (max-width: 420px) {
  .status-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .status-strip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .status-strip .live-source {
    white-space: normal;
  }

  .primary-composer form {
    grid-template-columns: 72px minmax(0, 1fr) 50px;
  }
}

@media (max-height: 620px) and (max-width: 900px) {
  .topbar {
    padding-top: 7px;
    padding-bottom: 6px;
  }

  .brand-mark,
  .live-source small,
  .primary-composer .composer-guard {
    display: none;
  }

  .quick-tags {
    display: none;
  }

  .timeline {
    padding-top: 4px;
    padding-bottom: 5px;
  }
}
