:root {
  color-scheme: dark;
  --bg: #0c0f14;
  --panel: #151b24;
  --panel-2: #1d2633;
  --line: #344052;
  --text: #fff;
  --muted: #aeb8c7;
  --accent: #47d7ff;
  --accent-2: #7cf2c7;
  --danger: #ff7a85;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #000; }
body { color: var(--text); font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", sans-serif; }
button { border: 0; color: inherit; font: inherit; }

#app {
  position: relative;
  width: min(100vw, 600px);
  height: min(100vh, 600px);
  margin: auto;
  overflow: hidden;
  background: radial-gradient(circle at 90% 0%, #163044 0, transparent 35%), var(--bg);
}

.screen { display: none; height: 100%; padding: 12px 16px; flex-direction: column; }
.screen.active { display: flex; }
.topbar, .quick-actions, .section-title, footer, .keyboard-head { display: flex; align-items: center; justify-content: space-between; }
.topbar { min-height: 58px; border-bottom: 1px solid var(--line); }
.topbar.compact { min-height: 52px; gap: 12px; }
.topbar strong { font-size: 25px; }
.topbar small { margin-left: 9px; color: var(--muted); font-size: 12px; }
.brand-dot { display: inline-block; width: 10px; height: 10px; margin-right: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 16px var(--accent); }
.pill { padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--accent-2); font-size: 12px; }

.query { display: flex; width: 100%; min-height: 62px; margin: 15px 0 10px; padding: 0 16px; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); text-align: left; }
.query span { max-width: 490px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.query b { color: var(--accent); font-size: 20px; }
.quick-actions { gap: 8px; }
.quick-actions button, .icon-button, .card, .link-card, .media-card, .keyboard-key, .candidate-row button, .error-card button { border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.quick-actions button { min-width: 0; flex: 1; padding: 10px 8px; }
button.primary { border-color: #269dc0; background: #12465a; }

.section-title { min-height: 46px; }
.section-title strong { font-size: 18px; }
.section-title span { color: var(--muted); font-size: 12px; }
.card-list { display: grid; min-height: 0; flex: 1; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: max-content; gap: 9px; overflow: hidden auto; scrollbar-width: none; }
.card-list::-webkit-scrollbar, .reader-body::-webkit-scrollbar, .reader-links::-webkit-scrollbar { display: none; }
.card { min-height: 95px; padding: 12px; text-align: left; }
.card strong, .link-card strong, .media-card strong { display: block; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.card p, .link-card p { display: -webkit-box; margin: 7px 0 0; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 16px; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.card small, .link-card small, .media-card small { display: block; margin-top: 8px; overflow: hidden; color: var(--accent); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

footer { min-height: 28px; margin-top: 6px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.icon-button { width: 42px; height: 38px; font-size: 22px; }
.page-identity { min-width: 0; flex: 1; }
.page-identity strong, .page-identity small { display: block; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-identity strong { font-size: 17px; }
.page-identity small { margin-top: 3px; color: var(--accent); }

.reader-body { min-height: 0; flex: 1; padding: 12px 5px 8px; overflow: hidden auto; outline: 0; }
.reader-body h1 { margin: 0 0 10px; font-size: 23px; line-height: 1.2; }
.reader-body h2 { margin: 16px 0 6px; color: var(--accent-2); font-size: 17px; }
.reader-body p { margin: 0 0 10px; color: #edf1f7; font-size: 15px; line-height: 1.52; }
.reader-links { display: flex; max-height: 112px; gap: 8px; overflow: hidden auto; }
.link-card, .media-card { min-width: 180px; max-width: 220px; padding: 9px 11px; text-align: left; }
.media-card { border-color: #305c69; }

.image-stage, .player-stage { display: grid; min-height: 0; flex: 1; margin: 10px 0; overflow: hidden; place-items: center; border: 1px solid var(--line); border-radius: 14px; background: #000; }
.image-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.caption { min-height: 32px; margin: 0; overflow: hidden; color: var(--muted); text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.player-stage { position: relative; }
#media-player, #embed-player { display: none; width: 100%; height: 100%; border: 0; background: #000; }
#media-player.show, #embed-player.show { display: block; }
#player-message { position: absolute; inset: 0; display: grid; padding: 30px; place-items: center; background: #000; color: var(--muted); text-align: center; }
#player-message.hidden { display: none; }

#error-screen { align-items: center; justify-content: center; }
.error-card { width: 82%; padding: 28px; border: 1px solid #5f3740; border-radius: 18px; background: #22171b; text-align: center; }
.error-icon { display: inline-grid; width: 54px; height: 54px; place-items: center; border-radius: 50%; background: var(--danger); color: #241014; font-size: 30px; font-weight: 900; }
.error-card h1 { margin: 16px 0 8px; font-size: 24px; }
.error-card p { color: var(--muted); line-height: 1.5; }
.error-card strong { display: block; margin-bottom: 18px; color: var(--accent); }
.error-card button { width: 100%; padding: 12px; }

.keyboard { display: none; position: absolute; inset: 8px; z-index: 10; padding: 13px; border: 1px solid #4c6678; border-radius: 16px; background: rgb(10 14 20 / 98%); box-shadow: 0 18px 60px #000; }
.keyboard.open { display: flex; flex-direction: column; }
.keyboard-head { min-height: 48px; }
.keyboard-head small, .keyboard-head strong { display: block; }
.keyboard-head small { color: var(--accent); font-size: 11px; }
.keyboard-head strong { max-width: 450px; overflow: hidden; font-size: 18px; text-overflow: ellipsis; white-space: nowrap; }
.candidate-row { display: grid; min-height: 42px; margin: 5px 0 9px; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.candidate-row button { min-width: 0; background: #173140; color: var(--accent-2); font-size: 18px; }
.keyboard-grid { display: grid; flex: 1; grid-template-columns: repeat(10, 1fr); grid-auto-rows: 1fr; gap: 5px; }
.keyboard-key { min-width: 0; min-height: 0; padding: 2px; font-size: 14px; }
.keyboard-key.wide { grid-column: span 2; }
.keyboard-key.action { background: #263142; color: var(--accent); font-size: 12px; }
.keyboard p { margin: 7px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

.focusable { outline: 0; transition: border-color 100ms ease, background 100ms ease, transform 100ms ease; }
.focusable:focus { border-color: var(--accent); background-color: #203344; box-shadow: 0 0 0 2px rgb(71 215 255 / 45%); transform: scale(.975); }
.reader-body:focus { box-shadow: inset 0 0 0 2px rgb(71 215 255 / 40%); }
.empty { grid-column: 1 / -1; padding: 40px; color: var(--muted); text-align: center; }

@media (max-width: 420px), (max-height: 420px) {
  .screen { padding: 8px 10px; }
  .topbar { min-height: 45px; }
  .query { min-height: 48px; margin: 8px 0; }
  .card { min-height: 80px; }
}

@media (prefers-reduced-motion: reduce) { .focusable { transition: none; } }
