:root {
  color-scheme: dark;
  --primary: #fcd535;
  --primary-active: #f0b90b;
  --primary-disabled: #3a3a1f;
  --canvas: #0b0e11;
  --surface: #1e2329;
  --surface-elevated: #2b3139;
  --surface-soft: #161a1f;
  --ink: #ffffff;
  --body: #eaecef;
  --muted: #707a8a;
  --muted-strong: #929aa5;
  --hairline: #2b3139;
  --hairline-strong: #3b424d;
  --on-primary: #181a20;
  --up: #0ecb81;
  --down: #f6465d;
  --info: #3b82f6;
  --youtube: #ff0033;
  --font: BinanceNova, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-number: BinancePlex, "Roboto Mono", "SFMono-Regular", Consolas, monospace;
  font-family: var(--font);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--canvas);
  color: var(--body);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p {
  margin: 0;
}

body.auth-loading::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--canvas);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
  padding: 28px;
}

.login-brand,
.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--font-number);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-logo {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  font-size: 12px;
}

.brand-logo.small {
  width: 36px;
  height: 36px;
}

.login-brand h1,
.app-brand h1 {
  color: var(--ink);
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

.login-brand p,
.brand-row p {
  color: var(--muted-strong);
  font-size: 12px;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

.login-form label,
.search-box,
.url-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.login-form span,
.search-box span,
.url-field span,
.eyebrow {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
}

.search-box {
  margin-top: 18px;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="url"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  outline: none;
  background: var(--surface-elevated);
  color: var(--ink);
  padding: 0 12px;
}

input::placeholder {
  color: var(--muted);
}

input:focus {
  border-color: var(--info);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

.app-shell {
  display: grid;
  grid-template-columns: 348px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow: hidden;
  border-right: 1px solid var(--hairline);
  background: var(--canvas);
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.badge {
  flex: 0 0 auto;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted-strong);
  background: var(--surface);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-ready {
  color: var(--on-primary);
  border-color: var(--primary);
  background: var(--primary);
}

.badge-muted {
  color: var(--muted-strong);
  background: var(--surface);
}

.stat-total {
  font-size: 12px;
  color: var(--muted-strong);
}

.stat-total strong {
  color: var(--primary);
  font-family: var(--font-number);
  font-weight: 700;
}

.sidebar-home-button {
  width: 100%;
  margin-top: 18px;
}

.history-list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
  border-top: 1px solid var(--hairline);
  margin-top: 18px;
  padding-top: 0;
  padding-right: 2px;
}

.text-view::-webkit-scrollbar {
  width: 10px;
}

.text-view::-webkit-scrollbar-thumb {
  background: var(--surface-elevated);
  border-radius: 999px;
}

.history-list {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.history-list::-webkit-scrollbar {
  display: none;
}

.history-item {
  width: 100%;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--surface);
  color: var(--body);
  padding: 8px;
  text-align: left;
  cursor: pointer;
}

.history-item:hover,
.history-item.active {
  border-color: var(--primary);
}

.history-item.active {
  background: #24251d;
}

.history-thumb {
  width: 92px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-elevated);
}

.history-thumb.thumb-broken {
  display: none;
}

.history-copy {
  min-width: 0;
}

.history-title {
  display: block;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  min-width: 0;
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  padding: 20px;
  background: var(--canvas);
}

.home-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding-top: clamp(40px, 18vh, 160px);
  gap: 18px;
  width: min(880px, 100%);
  margin: 0 auto;
}

.home-copy {
  display: grid;
  gap: 8px;
}

.home-copy h2 {
  color: var(--ink);
  font-size: 36px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0;
}

.home-copy p:not(.eyebrow) {
  max-width: 560px;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.5;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto auto;
  align-items: end;
  gap: 12px;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
  padding: 14px;
}

.url-preview {
  grid-column: 1 / -1;
  border-radius: 8px;
  overflow: hidden;
}

.url-preview img {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface);
  display: block;
}

.url-preview img.thumb-broken {
  background: var(--surface);
  opacity: 0.4;
}

.url-preview span {
  display: block;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}

.url-preview strong {
  display: block;
  color: var(--ink);
  font-family: var(--font-number);
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  flex: 0 0 auto;
  border-top: 1px solid var(--hairline);
  padding-top: 12px;
  margin-top: 12px;
}

.sidebar-footer .secondary-button {
  width: 100%;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  color: var(--body);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.toggle-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.primary-button,
.secondary-button,
.tab-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
}

.action-main {
  min-width: 148px;
}

.primary-button {
  background: var(--primary);
  color: var(--on-primary);
}

.primary-button:hover {
  background: var(--primary-active);
}

.primary-button:disabled {
  cursor: wait;
  color: var(--muted);
  background: var(--primary-disabled);
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: var(--hairline);
  background: var(--surface-elevated);
  color: var(--ink);
  text-decoration: none;
}

.secondary-button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.status-box {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  display: block;
  width: min(420px, calc(100vw - 32px));
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px 14px;
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.35;
  transition: opacity 140ms ease, transform 140ms ease;
}

.login-card .status-box {
  position: static;
  width: auto;
  transform: none;
  opacity: 1;
  pointer-events: auto;
  margin-top: 14px;
  display: none;
}

.status-box.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.login-card .status-box.show {
  display: block;
}

.status-box.error {
  color: var(--down);
  border-color: rgba(246, 70, 93, 0.45);
  background: rgba(246, 70, 93, 0.08);
}

.status-box.ok {
  color: var(--up);
  border-color: rgba(14, 203, 129, 0.4);
  background: rgba(14, 203, 129, 0.08);
}

.detail-panel {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
}

.empty-state {
  align-items: center;
  justify-content: center;
  min-height: 420px;
  text-align: center;
  color: var(--muted-strong);
}

.empty-state h2 {
  color: var(--ink);
  font-size: 24px;
  line-height: 1.2;
  margin-bottom: 8px;
}

.detail-header {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}

.thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-elevated);
}

.thumb-fallback {
  display: grid;
  place-items: center;
  border: 1px solid var(--hairline);
  color: var(--primary);
  font-family: var(--font-number);
  font-weight: 800;
}

.detail-title {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.detail-title h2 {
  color: var(--ink);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--surface-elevated);
  color: var(--muted-strong);
  padding: 4px 10px;
  font-size: 12px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 2px;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-soft);
}

.tab-button {
  background: transparent;
  border-color: var(--hairline);
  color: var(--muted-strong);
}

.tab-button.active {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
}

.tab-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.text-view {
  flex: 1;
  min-height: 300px;
  overflow: auto;
  padding: 20px;
  background: var(--canvas);
}

.text-view pre {
  margin: 0;
  color: var(--body);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 46vh) minmax(0, 54vh);
  }

  .sidebar {
    height: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
  }

  .workspace {
    height: 100%;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .url-field,
  .url-preview {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .login-view,
  .workspace,
  .sidebar {
    padding: 14px;
  }

  .login-card {
    padding: 20px;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .url-preview {
    grid-template-columns: 1fr;
  }

  .url-preview img {
    width: 100%;
  }

  .toggle-row {
    justify-content: flex-start;
  }

  .detail-header {
    grid-template-columns: 1fr;
  }

  .detail-title h2 {
    font-size: 20px;
  }

  .history-item {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .history-thumb {
    width: 76px;
  }
}
