@font-face {
  font-family: "Manga Temple";
  src: url("assets/fonts/mangat.ttf") format("truetype");
  font-weight: 100 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Manga Temple";
  src: url("assets/fonts/mangatb.ttf") format("truetype");
  font-weight: 700 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Manga Temple";
  src: url("assets/fonts/mangati.ttf") format("truetype");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "The Unseen";
  src: url("assets/fonts/the-unseen.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --page-bg: #eeeeee;
  --reader-bg: #ffffff;
  --ink: #161616;
  --muted: #666666;
  --reader-width: 920px;
  --bubble-bg: #ffffff;
  --bubble-border: #111111;
  --bubble-ink: #161616;
  --bubble-font: "Manga Temple", "Comic Sans MS", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

body.darkReader {
  color-scheme: dark;
  --page-bg: #080a0f;
  --reader-bg: #10131c;
  --ink: #f3f5fb;
  --muted: #aeb6c8;
}

body.darkReader .toolbar {
  background: rgba(12, 14, 22, 0.96);
  border-bottom-color: #252b3a;
  box-shadow: 0 2px 18px rgba(0, 0, 0, 0.42);
}

body.darkReader .toolbar .disclaimer {
  color: #d8deef;
}

body.darkReader select,
body.darkReader button,
body.darkReader input::file-selector-button,
body.darkReader .homeLink {
  border-color: #394154;
  background: #171b26;
  color: var(--ink);
}

body.darkReader button:hover,
body.darkReader input::file-selector-button:hover,
body.darkReader .homeLink:hover {
  background: #202636;
}

body.darkReader .reader {
  box-shadow: 0 0 36px rgba(0, 0, 0, 0.55);
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid #d8d8d8;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
}

.toolbar h1 {
  margin: 0 0 4px;
  font-size: 18px;
}

.toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar .disclaimer {
  margin-top: 4px;
  color: #333333;
  font-size: 12px;
  font-weight: 700;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: flex-end;
}

.controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

select,
button,
.fileControl {
  font: inherit;
}

select,
button,
input::file-selector-button {
  min-height: 34px;
  border: 1px solid #bcbcbc;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

select,
button {
  padding: 0 12px;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:hover,
input::file-selector-button:hover {
  background: #f4f4f4;
}

.menuButton {
  display: none;
}

.homeLink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid #bcbcbc;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  text-decoration: none;
}

.homeLink:hover {
  background: #f4f4f4;
}

.menuPage {
  min-height: 100vh;
}

.library {
  width: min(100%, 1100px);
  margin: 0 auto;
  padding: 28px 18px 48px;
}

.storyGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 22px;
}

.storyCard {
  overflow: hidden;
  border: 1px solid #d8d8d8;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.08);
  color: inherit;
  text-decoration: none;
}

.storyCard:hover {
  transform: translateY(-2px);
}

.storyCard img,
.storyCardCover {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #222222;
}

.storyCardCover {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: #ffffff;
  font-size: 28px;
  font-weight: 800;
  text-align: center;
}

.storyCardBody {
  padding: 16px 18px 18px;
}

.storyCardBody h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.storyCardBody p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.hamburgerIcon {
  display: inline-grid;
  gap: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.hamburgerIcon span {
  display: block;
  width: 16px;
  height: 2px;
  background: currentColor;
}

.reader {
  width: min(100%, var(--reader-width));
  margin: 0 auto;
  background: var(--reader-bg);
  box-shadow: 0 0 28px rgba(0, 0, 0, 0.14);
}

.panel {
  position: relative;
  margin: 0;
  line-height: 0;
  background: #ffffff;
  break-inside: avoid;
  page-break-inside: avoid;
}

.panel img {
  display: block;
  width: 100%;
  height: auto;
}

.bubble {
  position: absolute;
  z-index: 2;
  left: var(--bubble-left, 8%);
  top: var(--bubble-top, 8%);
  width: var(--bubble-width, 28%);
  min-width: 84px;
  padding: 12px 15px;
  border: 3px solid var(--bubble-border);
  border-radius: 999px;
  background: var(--bubble-bg);
  color: var(--bubble-ink);
  font-family: var(--bubble-font);
  font-size: var(--bubble-font-size, 19px);
  font-weight: 700;
  line-height: 1.18;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
  transform: rotate(var(--bubble-rotate, 0deg)) var(--bubble-style-transform, scale(1));
  transform-origin: center;
}

.type-dialogue {
  background: var(--bubble-bg);
}

.type-inner {
  background: #fffdf2;
  font-style: italic;
}

.type-note,
.type-noter,
.type-notes,
.type-notee,
.type-noteb {
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #ffffff;
  font-size: var(--bubble-font-size, 22px);
  font-weight: 800;
  line-height: 1.1;
  text-shadow:
    -2px -2px 0 #000000,
    0 -2px 0 #000000,
    2px -2px 0 #000000,
    -2px 0 0 #000000,
    2px 0 0 #000000,
    -2px 2px 0 #000000,
    0 2px 0 #000000,
    2px 2px 0 #000000;
  box-shadow: none;
}

.type-noter {
  font-family: var(--bubble-font);
  font-style: normal;
  letter-spacing: 0.01em;
}

.type-notes {
  font-family: var(--bubble-font);
  font-style: italic;
  letter-spacing: 0.05em;
  --bubble-style-transform: skew(-5deg);
}

.type-notee {
  font-family: var(--bubble-font);
  font-style: italic;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-shadow:
    -2px -2px 0 #000000,
    0 -2px 0 #000000,
    2px -2px 0 #000000,
    -2px 0 0 #000000,
    2px 0 0 #000000,
    -2px 2px 0 #000000,
    0 2px 0 #000000,
    2px 2px 0 #000000,
    0 0 8px rgba(255, 180, 220, 0.9);
}

.type-noteb {
  font-family: var(--bubble-font);
  font-weight: 900;
  letter-spacing: -0.02em;
  --bubble-style-transform: scaleX(1.12) scaleY(0.92);
}

.type-goblin {
  --bubble-bg: #1a240c;
  --bubble-border: #0b1206;
  isolation: isolate;
  padding: 16px 18px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #6eeb4a;
  font-family: "The Unseen", "Manga Temple", Arial, sans-serif;
  font-weight: 400;
  letter-spacing: 0.02em;
  box-shadow: none;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.55));
}

.type-goblin::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #1a240c;
  content: "";
  clip-path: polygon(
    2% 14%, 7% 4%, 15% 11%, 23% 2%, 32% 10%, 41% 1%, 51% 9%, 60% 2%, 70% 11%, 79% 3%, 88% 12%, 97% 5%,
    95% 18%, 100% 27%, 93% 36%, 100% 47%, 92% 57%, 100% 68%, 93% 78%, 99% 88%,
    90% 97%, 80% 92%, 71% 100%, 61% 93%, 51% 100%, 41% 92%, 31% 100%, 21% 93%, 11% 100%, 3% 91%,
    0% 80%, 7% 70%, 0% 59%, 8% 49%, 0% 38%, 7% 27%, 0% 17%
  );
}

.type-goblin::after {
  background: #1a240c;
  border: 0;
}

.shape-rounded {
  border-radius: 999px;
}

.shape-square {
  border-radius: 8px;
}

.shape-soft {
  border-radius: 22px;
}

.shape-none {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.shape-jagged {
  border-radius: 0;
}

.bubble[data-align="left"] {
  text-align: left;
}

.bubble[data-align="right"] {
  text-align: right;
}

.bubble[data-vertical="true"] {
  width: auto;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.bubble::after {
  position: absolute;
  width: 18px;
  height: 18px;
  border: solid var(--bubble-border);
  background: var(--bubble-bg);
  content: "";
  transform: rotate(45deg);
}

.tail-none::after {
  content: none;
}

.shape-none::after,
.type-note::after,
.type-noter::after,
.type-notes::after,
.type-notee::after,
.type-noteb::after {
  content: none;
}

.tail-bottom-left::after {
  bottom: -11px;
  left: 24%;
  border-width: 0 3px 3px 0;
}

.tail-bottom-right::after {
  right: 24%;
  bottom: -11px;
  border-width: 0 3px 3px 0;
}

.tail-top-left::after {
  top: -11px;
  left: 24%;
  border-width: 3px 0 0 3px;
}

.tail-top-right::after {
  top: -11px;
  right: 24%;
  border-width: 3px 0 0 3px;
}

.tail-left::after {
  top: 45%;
  left: -11px;
  border-width: 0 0 3px 3px;
}

.tail-right::after {
  top: 45%;
  right: -11px;
  border-width: 3px 3px 0 0;
}

.emptyState {
  padding: 48px 24px;
  text-align: center;
  line-height: 1.5;
}

.emptyState h2 {
  margin: 0 0 10px;
}

.emptyState p {
  max-width: 680px;
  margin: 0 auto;
  color: var(--muted);
}

.bottomChapterControls {
  display: none;
}

@media (max-width: 720px) {
  .toolbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .menuButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid #bcbcbc;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
  }

  .controls {
    display: none;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 12px;
    border: 1px solid #dddddd;
    border-radius: 10px;
    background: #ffffff;
  }

  body.controlsOpen .controls {
    display: flex;
  }

  .controls label,
  .controls select,
  .controls button,
  .controls .homeLink {
    width: 100%;
  }

  .bubble {
    left: max(2%, min(var(--bubble-left, 8%), calc(98% - min(var(--bubble-width, 28%), 68%))));
    width: min(var(--bubble-width, 28%), 68%);
    min-width: 0;
    border-width: 2px;
    padding: clamp(3px, 1.4vw, 6px) clamp(5px, 1.9vw, 8px);
    font-size: min(var(--bubble-font-size, 12px), clamp(9px, 2.7vw, 12px));
    line-height: 1.08;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
  }

  .shape-square {
    border-radius: 5px;
  }

  .shape-soft {
    border-radius: 12px;
  }

  .type-note,
  .type-noter,
  .type-notes,
  .type-notee,
  .type-noteb {
    left: max(2%, min(var(--bubble-left, 8%), calc(98% - min(var(--bubble-width, 28%), 80%))));
    width: min(var(--bubble-width, 28%), 80%);
    padding: 0;
    border: 0;
    background: transparent;
    font-size: min(var(--bubble-font-size, 18px), clamp(16px, 5.6vw, 24px));
    box-shadow: none;
    text-shadow:
      -1px -1px 0 #000000,
      0 -1px 0 #000000,
      1px -1px 0 #000000,
      -1px 0 0 #000000,
      1px 0 0 #000000,
      -1px 1px 0 #000000,
      0 1px 0 #000000,
      1px 1px 0 #000000;
  }

  .type-notee {
    text-shadow:
      -1px -1px 0 #000000,
      0 -1px 0 #000000,
      1px -1px 0 #000000,
      -1px 0 0 #000000,
      1px 0 0 #000000,
      -1px 1px 0 #000000,
      0 1px 0 #000000,
      1px 1px 0 #000000,
      0 0 6px rgba(255, 180, 220, 0.9);
  }

  .type-goblin {
    padding: clamp(8px, 2.4vw, 12px) clamp(10px, 2.8vw, 14px);
  }

  .bubble::after {
    width: 12px;
    height: 12px;
  }

  .tail-bottom-left::after {
    bottom: -8px;
    border-width: 0 2px 2px 0;
  }

  .tail-bottom-right::after {
    bottom: -8px;
    border-width: 0 2px 2px 0;
  }

  .tail-top-left::after {
    top: -8px;
    border-width: 2px 0 0 2px;
  }

  .tail-top-right::after {
    top: -8px;
    border-width: 2px 0 0 2px;
  }

  .tail-left::after {
    left: -8px;
    border-width: 0 0 2px 2px;
  }

  .tail-right::after {
    right: -8px;
    border-width: 2px 2px 0 0;
  }

  .bottomChapterControls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 18px 22px;
    background: #ffffff;
    border-top: 1px solid #dddddd;
  }

  .bottomChapterControls label {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 12px;
  }

  .bottomChapterControls select,
  .bottomChapterControls button {
    width: 100%;
    min-height: 38px;
  }
}

@media print {
  @page {
    margin: 0;
    size: auto;
  }

  body {
    background: #ffffff;
  }

  .toolbar,
  .homeLink,
  .bottomChapterControls {
    display: none;
  }

  .reader {
    width: 100%;
    margin: 0;
    box-shadow: none;
  }

  .panel {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .bubble {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
