/* រឿងល្អមើល: a living-room TV guide. Deep red and gold like a cinema sign, warm paper for the list,
   big type (Kantumruy Pro; Moul for the name, the classic Khmer title face) and big buttons. Every
   tap target is at least 48px; text never goes below about 17px. */

:root {
  color-scheme: light;
  --bg: #f6f0e6;
  --card: #fffdf8;
  --card-2: #efe5d6;
  --ink: #241a14;
  --ink-2: #4f4137;
  --ink-3: #75655a;
  --line: #e2d4bf;
  --red: #a3172c;
  --red-ink: #ffffff;
  --gold-soft: #f7e8c6;
  --gold-ink: #5a3d06;
  --head: #6b1220;
  --head-2: #430a14;
  --head-ink: #fff4de;
  --head-gold: #f3c869;
  --focus: #d08a12;
  --shadow: 0 1px 2px rgb(60 30 10 / 0.08), 0 8px 22px rgb(60 30 10 / 0.08);
  --kh: "Kantumruy Pro", "Noto Sans Khmer", "Khmer OS Siemreap", "Khmer UI", "Leelawadee UI", system-ui, sans-serif;
  --moul: "Moul", "Khmer OS Muol Light", "Khmer OS Muol", var(--kh);
  --base: 19px;
  --radius: 18px;
  --page: 1240px;
}

:root[data-size="large"] {
  --base: 22px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #151012;
    --card: #211a1d;
    --card-2: #2c2327;
    --ink: #f6eee4;
    --ink-2: #dacdbf;
    --ink-3: #b0a294;
    --line: #3b3035;
    --red: #d63a50;
    --red-ink: #ffffff;
    --gold-soft: #3b2d14;
    --gold-ink: #f6dca0;
    --head: #3f0a15;
    --head-2: #26060c;
    --focus: #f0b54a;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 22px rgb(0 0 0 / 0.35);
  }
}

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

html {
  font-size: var(--base);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--kh);
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.icon {
  width: 1.35em;
  height: 1.35em;
  flex: none;
}

/* ---------- top of the list ---------- */

.masthead {
  background: linear-gradient(160deg, var(--head), var(--head-2));
  color: var(--head-ink);
  padding: max(14px, env(safe-area-inset-top)) 16px 16px;
}

.masthead-inner {
  max-width: var(--page);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand-mark {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 14px;
  box-shadow: 0 0 0 2px rgb(243 200 105 / 0.5);
}

.brand-name {
  margin: 0;
  font-family: var(--moul);
  font-weight: 400;
  font-size: 1.5rem;
  line-height: 1.55;
  white-space: nowrap;
  color: var(--head-gold);
}

/* Narrow phones: the name stays on one line next to the text-size button. */
@media (max-width: 420px) {
  .brand-mark {
    display: none;
  }

  .brand-name {
    font-size: min(1.5rem, 8vw);
  }
}

.brand-tag {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.nowrap {
  white-space: nowrap;
}

.size-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid rgb(255 244 222 / 0.55);
  border-radius: 999px;
  background: transparent;
  color: var(--head-ink);
  font: 600 0.85rem/1.2 var(--kh);
  cursor: pointer;
}

.size-toggle[data-on="true"] {
  background: var(--head-gold);
  border-color: var(--head-gold);
  color: var(--head-2);
}

.size-glyph {
  font-size: 1.3em;
  line-height: 1;
}

.page {
  max-width: var(--page);
  margin: 0 auto;
  padding: 14px 16px 8px;
}

.hint {
  margin: 0 0 14px;
  color: var(--ink-2);
}

.shelf {
  margin-bottom: 28px;
}

.shelf-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin: 4px 0 12px;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.6;
}

.shelf-count {
  color: var(--ink-3);
  font-size: 0.9rem;
  font-weight: 500;
}

/* ---------- kinds ---------- */

.kinds {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
}

.kind {
  min-height: 50px;
  padding: 0 18px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: 600 1rem/1.2 var(--kh);
  cursor: pointer;
}

.kind[aria-pressed="true"] {
  background: var(--red);
  border-color: var(--red);
  color: var(--red-ink);
}

/* ---------- story cards ---------- */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

@media (min-width: 560px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease;
}

.card:active {
  transform: scale(0.985);
}

.thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--card-2);
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb.is-done img {
  filter: saturate(0.5) brightness(0.75);
}

.badge {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.6;
}

.badge .icon {
  width: 1.1em;
  height: 1.1em;
}

.badge-new {
  top: 10px;
  left: 10px;
  padding: 2px 16px;
  background: var(--red);
  color: #fff;
  font-size: 1rem;
}

.badge-part {
  top: 10px;
  right: 10px;
  background: rgb(0 0 0 / 0.75);
  color: #fff;
}

.badge-done {
  left: 10px;
  bottom: 10px;
  background: rgb(0 0 0 / 0.75);
  color: #fff;
}

.bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 8px;
  background: rgb(255 255 255 / 0.5);
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--red);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px 14px;
}

.card-title,
.card-sub {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.75;
  -webkit-line-clamp: 4;
  line-clamp: 4;
}

/* A phrase of a title, kept on one line when it fits (see phrased() in app.js). */
.ph {
  display: inline-block;
  max-width: 100%;
}

.card-sub {
  color: var(--ink-2);
  font-size: 0.95rem;
  line-height: 1.7;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.card-meta {
  margin-top: 2px;
  color: var(--ink-3);
  font-size: 0.9rem;
}

.card-left {
  color: var(--red);
  font-weight: 700;
}

.skeleton .thumb,
.skeleton .line {
  background: linear-gradient(90deg, var(--card-2), var(--line), var(--card-2));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton .line {
  display: block;
  height: 1em;
  margin: 8px 0;
  border-radius: 8px;
}

.skeleton .line.short {
  width: 55%;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

/* ---------- buttons, messages ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  padding: 6px 20px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  font: 600 1.02rem/1.35 var(--kh);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--red);
  border-color: var(--red);
  color: var(--red-ink);
}

.btn-quiet {
  background: transparent;
}

.btn-wide {
  width: 100%;
  margin-top: 18px;
}

.btn-small {
  min-height: 48px;
  padding: 4px 16px;
  font-size: 0.95rem;
}

.status:empty {
  display: none;
}

.status {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.status p {
  margin: 0;
}

.foot {
  max-width: var(--page);
  margin: 0 auto;
  padding: 8px 16px max(32px, env(safe-area-inset-bottom));
  color: var(--ink-2);
  font-size: 0.95rem;
}

.foot p {
  margin: 0 0 10px;
}

/* ---------- watching ---------- */

.watch-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: var(--head);
}

.btn-back {
  min-height: 52px;
  padding: 4px 18px 4px 10px;
  border-color: transparent;
  background: rgb(255 255 255 / 0.12);
  color: var(--head-ink);
}

.stage {
  position: relative;
  width: 100%;
  max-width: min(var(--page), calc(78vh * 16 / 9));
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  background: #000;
  container-type: size;
}

.stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.stage-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 16px;
  color: #fff;
  text-align: center;
}

/* Fullscreen: the real one (Android, computers) and the "fill the window" one (iPhone). */
.stage:fullscreen {
  max-width: none;
  aspect-ratio: auto;
}

.stage:-webkit-full-screen {
  max-width: none;
  aspect-ratio: auto;
}

body.filled {
  overflow: hidden;
}

body.filled .stage {
  position: fixed;
  inset: 0;
  z-index: 100;
  max-width: none;
  aspect-ratio: auto;
}

/* Upright, a black bar on top holds the close button and the hint, off YouTube's own buttons. */
body.filled .stage iframe {
  top: calc(env(safe-area-inset-top) + 68px);
  bottom: env(safe-area-inset-bottom);
  height: auto;
}

/* A phone turned sideways while watching: the video takes the whole screen. */
@media (orientation: landscape) and (max-height: 500px) {
  body.watching {
    overflow: hidden;
  }

  body.watching .stage {
    position: fixed;
    inset: 0;
    z-index: 100;
    max-width: none;
    aspect-ratio: auto;
  }
}

.unfill {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 4px 16px 4px 12px;
  border: 0;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.7);
  color: #fff;
  font: 600 0.95rem/1.3 var(--kh);
  cursor: pointer;
}

.fill-hint {
  display: none;
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  right: 12px;
  max-width: 45%;
  margin: 0;
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: end;
  opacity: 0.85;
}

body.filled .fill-hint {
  display: block;
}

/* Sideways, the video gets the whole screen; turning the phone upright again shows the bar. */
@media (orientation: landscape) {
  body.filled .fill-hint {
    display: none;
  }

  body.filled .stage iframe {
    top: 0;
    bottom: 0;
  }
}

/* What shows over the video when a story ends or will not play. */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 14px;
  background: rgb(14 9 11 / 0.9);
  color: #fff;
}

.ov-box {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 600px;
  text-align: center;
}

.ov-box p {
  margin: 0;
}

.ov-done {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1.2rem;
  font-weight: 700;
}

.ov-next {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 14px;
  background: rgb(255 255 255 / 0.1);
  text-align: start;
}

.ov-next img {
  width: 36%;
  flex: none;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 10px;
}

.ov-next span {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  font-weight: 600;
  line-height: 1.7;
}

.ov-label {
  color: var(--head-gold);
  font-weight: 700;
}

.ov-count {
  opacity: 0.9;
}

.ov-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.ov-actions .btn {
  min-height: 52px;
}

.btn-ghost {
  border-color: rgb(255 255 255 / 0.5);
  background: transparent;
  color: #fff;
}

/* A phone held upright leaves a short video area: keep only what matters. */
@container (max-height: 300px) {
  .overlay {
    padding: 8px;
  }

  .ov-box {
    gap: 6px;
  }

  .ov-label,
  .ov-next img {
    display: none;
  }

  .ov-next {
    padding: 0;
    background: none;
    justify-content: center;
    text-align: center;
  }

  .ov-next span {
    -webkit-line-clamp: 1;
    line-clamp: 1;
    font-size: 0.9rem;
  }

  .ov-done {
    font-size: 1rem;
  }

  .ov-count {
    font-size: 0.9rem;
  }

  .ov-actions .btn {
    min-height: 46px;
    padding: 4px 14px;
    font-size: 0.9rem;
  }
}

.watch-body {
  max-width: var(--page);
  margin: 0 auto;
  padding: 14px 16px 4px;
}

.w-title {
  margin: 0 0 2px;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.7;
}

.w-title:focus {
  outline: none;
}

.w-sub {
  margin: 0 0 2px;
  color: var(--ink-2);
}

.w-meta {
  margin: 0 0 10px;
  color: var(--ink-3);
  font-size: 0.92rem;
}

/* One big button per row on a phone, so no label ever breaks in the middle of a word. */
.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  margin: 12px 0;
}

.controls .btn span {
  white-space: nowrap;
}

@media (min-width: 600px) {
  .controls {
    grid-template-columns: repeat(3, max-content);
  }
}

.note {
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--gold-soft);
  color: var(--gold-ink);
}

.note-strong {
  font-weight: 700;
}

.resume {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}

.resume .btn {
  background: var(--card);
}

.tip {
  margin: 6px 0 0;
  color: var(--ink-3);
  font-size: 0.9rem;
}

.watch-more {
  max-width: var(--page);
  margin: 0 auto;
  padding: 10px 16px max(32px, env(safe-area-inset-bottom));
}

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

  .skeleton .thumb,
  .skeleton .line {
    animation: none;
  }
}
