/* ดองเก่งเลยน้า: manga ink on paper. Series with new chapters are drawn as manga panels
   (ink border, hard offset shadow) with the count in a speech bubble; caught-up ones stay quiet. */

:root {
  --paper: #fbfbf8;
  --panel: #ffffff;
  --ink: #1b1c1a;
  --muted: #676b63;
  --line: #d9dcd3;
  --brine: #3d7a36; /* pickling brine: main actions */
  --brine-ink: #ffffff;
  --pop: #ffdd3c; /* speech bubble */
  --pop-ink: #1b1c1a;
  --danger: #b3261e;
  --tone: rgb(27 28 26 / 0.13); /* screentone dots */
  --display: "Mitr", "Sukhumvit Set", "Noto Sans Thai", sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "Sukhumvit Set", "Noto Sans Thai", "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141713;
    --panel: #1d211c;
    --ink: #eceee6;
    --muted: #9da394;
    --line: #343a31;
    --brine: #8cc46f;
    --brine-ink: #10200b;
    --pop: #ffd43b;
    --pop-ink: #1b1c1a;
    --danger: #ff8a80;
    --tone: rgb(236 238 230 / 0.09);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--body);
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; font-family: var(--display); font-weight: 600; line-height: 1.25; }
h2 { font-size: 21px; margin-bottom: 12px; }
h3 { font-size: 17px; margin-bottom: 6px; }
p { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0; }
[hidden] { display: none !important; }
code { font-size: 0.9em; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; overflow-wrap: anywhere; }
:focus-visible { outline: 3px solid var(--brine); outline-offset: 2px; }

/* ---- controls ---- */
button, .button {
  font: inherit;
  font-size: 15px;
  border: 1.5px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 14px;
  min-height: 40px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:disabled { opacity: 0.5; }
.primary {
  background: var(--brine);
  border-color: var(--ink);
  color: var(--brine-ink);
  font-family: var(--display);
  font-weight: 500;
  box-shadow: 2px 2px 0 var(--ink);
}
.primary:active { transform: translate(2px, 2px); box-shadow: none; }
.danger { color: var(--danger); }
.link { border: none; background: none; box-shadow: none; color: var(--brine); padding: 8px 0; min-height: 0; }
.link.danger { color: var(--danger); }
.round { width: 40px; padding: 0; border-radius: 50%; font-size: 19px; }

input, textarea, select {
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming on focus */
  color: var(--ink);
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
input, textarea { width: 100%; padding: 10px 12px; }
input:focus, textarea:focus, select:focus { border-color: var(--ink); outline: none; }
label { display: block; margin: 12px 0; font-size: 14px; }
label input, label textarea { margin-top: 6px; }

/* ---- masthead: the app's name on a strip of screentone ---- */
.masthead {
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background:
    radial-gradient(var(--tone) 1.1px, transparent 1.3px) 0 0 / 7px 7px,
    var(--paper);
  border-bottom: 2px solid var(--ink);
}
.masthead-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 720px; margin: 0 auto; }
.logo {
  font-size: clamp(26px, 7.5vw, 34px);
  letter-spacing: -0.01em;
  line-height: 1.1;
  /* paper-coloured outline so the name stays crisp over the dots */
  text-shadow: 0 0 6px var(--paper), 0 0 2px var(--paper);
}
.logo-en { display: inline-block; font-family: var(--body); font-weight: 500; font-size: 13px; letter-spacing: 0.01em; color: var(--muted); vertical-align: 0.35em; }
.masthead-actions { display: flex; gap: 8px; flex: none; }
.summary {
  max-width: 720px;
  margin: 4px auto 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 16px;
  color: var(--ink);
  text-shadow: 0 0 6px var(--paper);
}

main { max-width: 720px; margin: 0 auto; padding: 14px 16px 40px; }

/* ---- toolbar ---- */
.toolbar { display: grid; gap: 10px; margin-bottom: 14px; }
.toolbar-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sort { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; color: var(--muted); }
.sort select, .inline select { padding: 6px 10px; min-height: 38px; font-size: 15px; }
.chip { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 14px; white-space: nowrap;
  border: 1.5px solid var(--line); border-radius: 999px; padding: 6px 12px; background: var(--panel); cursor: pointer; }
.chip input { width: auto; margin: 0; accent-color: var(--brine); }
.chip:has(input:checked) { border-color: var(--ink); background: var(--pop); color: var(--pop-ink); }
.hint { font-size: 13px; color: var(--muted); }

/* ---- list ---- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "open count" "foot foot";
  align-items: start;
  gap: 8px 10px;
  padding: 10px 12px 10px 10px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 8px;
}
/* New chapters: a manga panel. */
.item.has-new { border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.item .open { grid-area: open; color: inherit; text-decoration: none; min-width: 0; display: flex; align-items: flex-start; gap: 12px; }
.item .text { min-width: 0; display: block; padding-top: 1px; }
.cover {
  flex: none;
  width: 54px;
  height: 76px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--line);
  display: grid;
  place-items: center;
}
.item.has-new .cover { outline: 1.5px solid var(--ink); }
.item:not(.has-new) .cover { width: 40px; height: 56px; } /* caught up: smaller, so new ones stand out */
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-letter { font-family: var(--display); font-weight: 600; font-size: 22px; color: var(--muted); }
.item .title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 600;
  line-height: 1.3;
}
.item:not(.has-new) .title { font-weight: 500; }
.item .meta { display: block; font-size: 13px; color: var(--muted); margin-top: 3px; }
.item .warn { display: block; font-size: 13px; color: var(--danger); margin-top: 3px; }
.item .pin { font-size: 0.85em; }

/* The count, as a speech bubble with a tail pointing at the cover. */
.count {
  grid-area: count;
  position: relative;
  justify-self: end;
  margin: 2px 2px 0 0;
  min-width: 48px;
  padding: 2px 11px 3px;
  text-align: center;
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  color: var(--pop-ink);
  background: var(--pop);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
.count::after {
  content: "";
  position: absolute;
  left: 8px;
  bottom: -7px;
  width: 9px;
  height: 9px;
  background: var(--pop);
  border-left: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: skewY(-35deg) rotate(-10deg);
}

/* Bottom row: website on the left, buttons on the right, so the title gets the full width above. */
.item .foot { grid-area: foot; display: flex; align-items: center; gap: 6px; }
.item .foot .host { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }
.item .foot button { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.item .foot .handle {
  touch-action: none; /* the finger drags the item instead of scrolling the page */
  -webkit-touch-callout: none;
  cursor: grab;
  font-size: 20px;
  width: 40px;
  padding: 0;
}
.item.dragging { position: relative; z-index: 3; transform: rotate(-1deg) scale(1.02); box-shadow: 8px 8px 0 var(--ink); }
body.dragging-active { -webkit-user-select: none; user-select: none; }

.empty { text-align: center; padding: 48px 12px; color: var(--muted); }

/* ---- sheets and dialogs ---- */
.sheet, dialog {
  background: var(--panel);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 5px 5px 0 var(--ink);
}
.login { max-width: 380px; margin: 40px auto; padding: 20px; }
.login .muted { margin-bottom: 12px; }
.login button { width: 100%; margin-top: 12px; }
dialog {
  width: min(520px, calc(100vw - 28px));
  max-height: calc(100dvh - 40px);
  padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
details { margin: 4px 0; }
summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.inline { display: flex; align-items: center; gap: 8px; margin: 0; }

.setting { padding: 14px 0; border-top: 1.5px solid var(--line); }
.setting:first-of-type { border-top: none; padding-top: 0; }
.setting .muted { font-size: 14px; }
.status { margin-top: 8px; font-size: 14px; }
.steps { margin: 10px 0; padding-left: 22px; font-size: 14px; display: grid; gap: 6px; }
.copy { display: flex; gap: 8px; align-items: center; }
.copy code { flex: 1; min-width: 0; padding: 8px 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
  .item.dragging { transform: none; }
}
