:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  background: #f4f5f0;
  color: #171b1a;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  min-height: 100svh;
  background: #f4f5f0;
  -webkit-font-smoothing: antialiased;
}
body[data-mode="watching"] { background: #080a09; overflow: hidden; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.app-shell { min-height: 100svh; }

.loading-state,
.loading-panel {
  min-height: 100svh;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
}
.loading-panel strong { font-size: 28px; }
.loading-panel span { color: #66706c; }

.page-shell {
  width: min(100%, 720px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}

.auth-page {
  display: grid;
  align-content: center;
  gap: 24px;
  width: min(100%, 520px);
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-header img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  background: #f5c343;
  box-shadow: 0 8px 20px rgb(24 35 30 / 12%);
}
.brand-header p {
  margin: 0 0 2px;
  color: #67716d;
  font-size: 14px;
  font-weight: 650;
}
.brand-header h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0;
}

.auth-panel,
.manage-panel,
.library-panel,
.history-panel {
  background: #fff;
  border: 1px solid #dfe3dd;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgb(24 35 30 / 8%);
}
.auth-panel { padding: 22px; }
.manage-panel { margin-top: 28px; padding: 24px; }
.library-panel,
.history-panel { margin-top: 14px; padding: 24px; }

form { display: grid; gap: 18px; }
.field { display: grid; gap: 8px; }
.field > span,
.duration-field legend {
  color: #414b47;
  font-size: 14px;
  font-weight: 700;
}
.field input,
.field textarea {
  width: 100%;
  border: 1px solid #bdc5c0;
  border-radius: 6px;
  background: #fbfcfa;
  color: #171b1a;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field input { min-height: 48px; padding: 0 13px; }
.field textarea {
  min-height: 92px;
  padding: 12px 13px;
  resize: vertical;
  line-height: 1.5;
}
.field input:focus,
.field textarea:focus {
  border-color: #20875c;
  box-shadow: 0 0 0 3px rgb(32 135 92 / 14%);
}

.duration-field { min-width: 0; margin: 0; padding: 0; border: 0; }
.duration-field legend { margin-bottom: 8px; }
.star-entry {
  width: min(100%, 220px);
  min-height: 48px;
  display: flex;
  align-items: center;
  border: 1px solid #bdc5c0;
  border-radius: 6px;
  background: #fbfcfa;
  overflow: hidden;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.star-entry:focus-within {
  border-color: #20875c;
  box-shadow: 0 0 0 3px rgb(32 135 92 / 14%);
}
.star-entry input {
  width: 0;
  min-width: 0;
  flex: 1;
  align-self: stretch;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: #171b1a;
  font-size: 18px;
  font-weight: 750;
  outline: 0;
}
.star-entry span { padding: 0 14px; color: #66706c; font-size: 14px; font-weight: 700; }
.primary-button,
.secondary-button,
.danger-button,
.text-button,
.reload-button,
.stop-button {
  min-height: 48px;
  border-radius: 6px;
  font-weight: 750;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary-button {
  border: 1px solid #171b1a;
  background: #171b1a;
  color: #fff;
  padding: 0 18px;
}
.primary-button:active { background: #343b38; }
.secondary-button {
  border: 1px solid #bdc5c0;
  background: #fff;
  color: #2f3935;
  padding: 0 16px;
}
.danger-button {
  border: 1px solid #cf432c;
  background: #cf432c;
  color: #fff;
  padding: 0 16px;
}
.text-button {
  border: 0;
  background: transparent;
  color: #525d58;
  padding: 0 16px;
}
button:disabled { cursor: wait; opacity: .65; }
.auth-panel .primary-button { width: 100%; }
.action-row {
  display: block;
}
.action-row .start-button { width: 100%; }

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.panel-heading h2 { margin: 0; font-size: 20px; line-height: 1.2; letter-spacing: 0; }
.panel-heading span { color: #67716d; font-size: 13px; font-weight: 700; }
.library-form { gap: 14px; }
.library-form-grid {
  display: grid;
  grid-template-columns: minmax(140px, .7fr) minmax(0, 1.3fr);
  gap: 12px;
}
.library-form-grid textarea { min-height: 72px; }
.library-save-button { justify-self: start; min-width: 128px; }
.library-list,
.history-list {
  display: grid;
  gap: 0;
  margin-top: 22px;
  border-top: 1px solid #e4e7e2;
}
.library-empty { margin: 0; padding: 20px 0 2px; color: #77807c; font-size: 14px; }
.library-item {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid #e4e7e2;
}
.library-copy { min-width: 0; }
.library-copy h3 { margin: 0 0 5px; font-size: 15px; line-height: 1.35; letter-spacing: 0; }
.library-copy p {
  margin: 0;
  overflow: hidden;
  color: #6b7470;
  font-size: 12px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-time {
  display: block;
  margin: 0 0 4px;
  color: #20875c;
  font-size: 12px;
  font-weight: 700;
}
.library-actions { display: flex; align-items: center; gap: 6px; }
.library-actions button {
  min-width: 48px;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid #c8ceca;
  border-radius: 6px;
  background: #fff;
  color: #34403b;
  font-size: 13px;
  font-weight: 700;
}
.library-actions .delete-link-button { border-color: transparent; color: #ad3927; }

.form-message {
  margin: -6px 0 0;
  padding: 10px 12px;
  border-left: 3px solid #cf432c;
  background: #fff0ec;
  color: #9a2d1c;
  font-size: 14px;
  line-height: 1.45;
}
.form-message[data-kind="success"] {
  border-color: #20875c;
  background: #e7f5ed;
  color: #176a48;
}
.error-panel p { margin: 0; color: #704036; line-height: 1.6; }

.watch-page {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #080a09;
  color: #fff;
}
.watch-bar {
  min-height: calc(62px + env(safe-area-inset-top));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: end;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid #282d2b;
  background: #111412;
}
.watch-title {
  overflow: hidden;
  color: #dce1df;
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.countdown {
  min-width: 104px;
  color: #f5c343;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
}
.countdown.urgent { color: #ff6d52; }
.reload-button,
.stop-button {
  min-height: 38px;
  border: 1px solid #444b48;
  background: #1d2220;
  color: #ecefed;
}
.reload-button {
  width: 40px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}
.stop-button {
  justify-self: end;
  padding: 0 12px;
  font-size: 13px;
}
.player-shell {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
}
.player-shell iframe {
  display: block;
  width: min(100vw, calc((100svh - 63px) * 16 / 9));
  height: min(calc(100vw * 9 / 16), calc(100svh - 63px));
  max-width: 100%;
  border: 0;
  background: #000;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(0 0 0 / 74%);
}
.stop-dialog {
  width: min(100%, 420px);
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  color: #171b1a;
  box-shadow: 0 24px 70px rgb(0 0 0 / 38%);
}
.stop-dialog h2 { margin: 0 0 18px; font-size: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 520px) {
  .manage-page { padding-left: 14px; padding-right: 14px; }
  .manage-panel,
  .library-panel,
  .history-panel { padding: 18px 14px; }
  .library-form-grid { grid-template-columns: 1fr; }
  .library-save-button { width: 100%; }
  .library-item { grid-template-columns: 1fr; gap: 10px; }
  .library-copy p { white-space: normal; overflow-wrap: anywhere; }
  .library-actions { justify-content: flex-end; }
  .watch-bar { grid-template-columns: minmax(0, 1fr) auto auto; }
  .watch-title { grid-column: 1; grid-row: 1; }
  .countdown { grid-column: 1; grid-row: 2; justify-self: start; }
  .reload-button { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .stop-button { grid-column: 3; grid-row: 1 / span 2; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .watch-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    background: rgb(17 20 18 / 90%);
  }
  .player-shell { min-height: 100svh; }
  .player-shell iframe { width: min(100vw, calc(100svh * 16 / 9)); height: min(calc(100vw * 9 / 16), 100svh); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* Child View & V1 Upgrade Styles */
.child-page {
  display: grid;
  gap: 20px;
}

.child-top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-link-btn {
  background: #fff;
  border: 1px solid #bdc5c0;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  color: #67716d;
  cursor: pointer;
}

.admin-link-btn:hover {
  color: #171b1a;
  border-color: #67716d;
}

.star-banner {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid #f59e0b;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 10px 25px rgb(245 158 11 / 15%);
}

.star-banner-info h2 {
  margin: 0;
  font-size: 16px;
  color: #92400e;
}

.star-banner-info p {
  margin: 4px 0 0;
  font-size: 12px;
  color: #b45309;
}

.star-display {
  font-size: 28px;
  font-weight: 900;
  color: #d97706;
  letter-spacing: -0.5px;
}

.redeem-card {
  background: #fff;
  border: 1px solid #dfe3dd;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 8px 30px rgb(24 35 30 / 6%);
}

.redeem-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.redeem-form {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.redeem-input {
  flex: 1;
  text-transform: uppercase;
  font-family: monospace;
  font-size: 20px;
  letter-spacing: 4px;
  text-align: center;
  font-weight: bold;
}

.catalog-panel {
  background: #fff;
  border: 1px solid #dfe3dd;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 8px 30px rgb(24 35 30 / 6%);
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.cartoon-card {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px;
  background: #fafaf9;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cartoon-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.cartoon-card h3 {
  margin: 0;
  font-size: 15px;
  color: #1c1917;
  line-height: 1.4;
}

.refund-button {
  background: #059669;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-weight: bold;
  font-size: 13px;
  cursor: pointer;
}

.refund-button:hover {
  background: #047857;
}

.duration-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.duration-pill {
  border: 1px solid #cbd5e1;
  background: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.duration-pill.active {
  background: #f59e0b;
  color: #fff;
  border-color: #d97706;
}

