:root {
  color-scheme: dark;
  --bg: #0e0f12;
  --panel: #17191d;
  --line: #31343c;
  --text: #f2f3f5;
  --muted: #a8b0bd;
  --hover: #22262e;
  --current: #2a3142;
  --field: #0e0f12;
  --line-strong: #3a3e48;
  --danger-bg: #3a2428;
  --danger-text: #ffd7d7;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: #3d4d68;
  color: #fff;
}

:focus-visible {
  outline: 2px solid #d7e2f5;
  outline-offset: 2px;
}


/* hidden must beat display:grid / flex on the same nodes */
[hidden],
.stage-message[hidden],
#player-wrap[hidden],
.play-error[hidden] {
  display: none !important;
}

.app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: var(--safe-top);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
}

.top {
  flex: none;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  font-weight: 600;
}

.ghost,
.retry,
.primary {
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--hover);
  color: var(--text);
  min-height: 40px;
  padding: 8px 14px;
  cursor: pointer;
}

.ghost:hover,
.retry:hover {
  background: #2c313b;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
}

.library {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.list-head {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 8px;
}

h2 {
  font-size: 14px;
  font-weight: 600;
}

.count {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.rows {
  list-style: none;
  margin: 0;
  padding: 4px 8px 16px;
  overflow: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.rows > .empty {
  padding: 16px 10px;
  color: var(--muted);
  font-size: 14px;
}

.rows > .empty button {
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--hover);
  color: var(--text);
  min-height: 44px;
  padding: 8px 14px;
  cursor: pointer;
}

.row {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  touch-action: manipulation;
}

.row:hover {
  background: var(--hover);
}

.row.is-current {
  background: var(--current);
}

.name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.size {
  flex: none;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 8px;
  color: var(--text);
}

.stage {
  min-width: 0;
  min-height: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  overflow: auto;
}

.stage-message,
.frame {
  width: min(100%, 1100px);
  margin: 0 auto;
}

.stage-message {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  background: #000;
  color: #d5dbe6;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.frame {
  --media-accent-color: #d7e2f5;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.frame video-skin {
  display: grid;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.frame video {
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
}

.now {
  width: min(100%, 1100px);
  margin: 0 auto;
  overflow-wrap: anywhere;
  font-size: 14px;
  color: var(--muted);
}

.play-error {
  width: min(100%, 1100px);
  margin: -4px auto 0;
  color: var(--danger-text);
  font-size: 14px;
}

body.login {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, var(--safe-top)) max(24px, var(--safe-right)) max(24px, var(--safe-bottom)) max(24px, var(--safe-left));
}

.card {
  width: min(100%, 400px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px;
}

.card h1 {
  font-size: 22px;
}

.lead {
  color: var(--muted);
  font-size: 14px;
}

.card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

input {
  background: var(--field);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  min-height: 48px;
  padding: 12px;
  font-size: 16px;
}

.primary {
  width: 100%;
  min-height: 48px;
  background: var(--text);
  color: #121417;
  border-color: var(--text);
  font-weight: 600;
}

.primary:hover {
  background: #fff;
}

.error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

/* Phone / narrow */
@media (max-width: 760px) {
  .top {
    min-height: 48px;
    padding: 0 12px;
  }

  h1 {
    font-size: 16px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .stage {
    order: 1;
    flex: none;
    padding: 10px 10px 8px;
    justify-content: flex-start;
    overflow: visible;
  }

  .stage-message {
    aspect-ratio: auto;
    min-height: 120px;
    max-height: 28vh;
    border-radius: 8px;
    font-size: 15px;
  }

  .frame {
    border-radius: 8px;
  }

  .frame video-skin {
    max-height: min(42vh, 56vw);
    aspect-ratio: 16 / 9;
  }

  .now {
    font-size: 13px;
    padding: 0 2px;
  }

  .library {
    order: 2;
    flex: 1;
    min-height: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .list-head {
    padding: 10px 12px 6px;
  }

  .rows {
    padding: 2px 6px calc(12px + var(--safe-bottom));
  }

  .row {
    min-height: 56px;
    padding: 12px;
  }

  .name {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.35;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .size {
    display: none;
  }

  .stage-message {
    min-height: 96px;
  }
}

/* Landscape phone: side-by-side compact */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .workspace {
    display: grid;
    grid-template-columns: minmax(180px, 42vw) minmax(0, 1fr);
  }

  .library {
    order: 0;
    border-right: 1px solid var(--line);
    border-top: 0;
  }

  .stage {
    order: 0;
    padding: 8px;
    justify-content: center;
  }

  .stage-message,
  .frame video-skin {
    max-height: calc(100dvh - 72px);
    aspect-ratio: 16 / 9;
  }

  .row {
    min-height: 44px;
    padding: 8px 10px;
  }

  .name {
    white-space: nowrap;
    display: block;
    -webkit-line-clamp: unset;
  }
}
