:root {
  color-scheme: dark;
  --bg: #0c0f12;
  --panel: #151a1f;
  --panel-soft: #1b2228;
  --ink: #eef3f7;
  --muted: #a7b1ba;
  --line: #303941;
  --accent: #8b5cf6;
  --accent-strong: #7c3aed;
  --danger: #ff6b61;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #20272d;
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover {
  border-color: #56636d;
  background: #252e35;
  transform: translateY(-1px);
}

button.dangerButton {
  width: 100%;
  margin-top: 8px;
  border-color: rgba(255, 107, 97, 0.48);
  color: #ffd6d2;
  background: #2b1819;
}

button.dangerButton:hover {
  border-color: var(--danger);
  background: #3a1d1f;
}

button.primary {
  width: 100%;
  margin-top: 10px;
  border-color: var(--accent);
  background: var(--accent);
  color: #061311;
  font-weight: 700;
}

button.primary:hover {
  background: var(--accent-strong);
}

button.compactPrimary {
  margin: 0 0 8px;
}

.statusText {
  min-height: 18px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.app {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-rows: 56px minmax(0, 1fr);
  min-height: 100vh;
}

.appHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #0f1418;
}

.appHeader strong {
  font-size: 16px;
}

.appHeader nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.navButton {
  min-height: 34px;
  padding: 0 12px;
}

.navButton.active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
  font-weight: 700;
}

.editorHeader {
  grid-column: 1 / -1;
}

.authView,
.libraryView {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

.authView {
  display: grid;
  place-items: center;
  padding: 24px;
}

.authPanel {
  width: min(390px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  animation: riseIn 260ms ease both;
}

.authPanel h1 {
  margin: 0 0 16px;
  font-size: 28px;
  letter-spacing: 0;
}

.libraryView {
  padding: 0 22px 22px;
}

.libraryHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 16px;
}

.libraryActions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.quotaBadge {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(139, 92, 246, 0.45);
  border-radius: 6px;
  padding: 0 10px;
  background: rgba(139, 92, 246, 0.12);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.quotaBadge.low {
  border-color: rgba(255, 107, 97, 0.55);
  background: rgba(255, 107, 97, 0.14);
}

.libraryHeader h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0;
}

.libraryHeader p {
  margin: 4px 0 0;
  color: var(--muted);
}

.addSeriesButton {
  width: auto;
  min-width: 128px;
  margin: 0;
}

.searchField {
  max-width: 520px;
  margin-bottom: 18px;
}

.seriesModal {
  width: min(560px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.seriesModal::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.seriesForm {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.seriesForm .field {
  margin-bottom: 0;
}

.seriesGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.seriesCard {
  min-height: 270px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
  animation: riseIn 220ms ease both;
}

.seriesCard:hover {
  transform: translateY(-3px);
  border-color: rgba(139, 92, 246, 0.7);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.34);
}

.seriesCover {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #20272d;
}

.seriesInfo {
  padding: 10px;
}

.seriesInfo strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seriesInfo span {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.editSeriesBtn {
  width: calc(100% - 20px);
  min-height: 30px;
  margin: 0 10px 10px;
  border-color: rgba(139, 92, 246, 0.45);
  background: rgba(139, 92, 246, 0.13);
}

.chapterTools {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 0 10px 10px;
}

.chapterTools input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  color: var(--ink);
  background: var(--panel-soft);
}

.chapterList {
  display: grid;
  gap: 6px;
  padding: 0 10px 10px;
  max-height: 116px;
  overflow: auto;
}

.chapterButton {
  min-height: 32px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapterRow {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 6px;
}

.chapterSelect {
  margin: 0;
}

.deleteChapterBtn {
  min-height: 30px;
  border-color: rgba(255, 107, 97, 0.45);
  background: rgba(255, 107, 97, 0.12);
}

.storageStats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.storageStats span {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
}

.settingsTools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 56px);
  padding: 16px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #101418;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  color: var(--ink);
  background: var(--panel-soft);
  font-size: 14px;
  font-weight: 400;
}

.field input[type="color"] {
  height: 38px;
  padding: 4px;
}

.field textarea {
  resize: vertical;
  line-height: 1.35;
}

.actions,
.row,
.grid2,
.fontTools {
  display: grid;
  gap: 8px;
}

.actions {
  grid-template-columns: repeat(3, 1fr);
}

.downloadRow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.downloadRow button {
  width: 100%;
}

.row {
  grid-template-columns: 1fr auto auto;
  align-items: center;
  margin-bottom: 10px;
}

.grid2,
.fontTools {
  grid-template-columns: 1fr 1fr;
}

.fontTools {
  margin: -2px 0 10px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.boxList {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.pageList {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 0 10px;
}

.pageItem {
  min-height: 32px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 7px;
  background: var(--panel-soft);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.pageItem.active {
  border-color: var(--accent);
  color: var(--ink);
  outline: 2px solid rgba(56, 182, 167, 0.18);
}

.boxItem {
  display: grid;
  grid-template-columns: 20px 28px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  background: var(--panel-soft);
  cursor: pointer;
}

.boxItem.active {
  border-color: var(--accent);
  outline: 2px solid rgba(139, 92, 246, 0.2);
}

.boxIndex {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(56, 182, 167, 0.16);
  color: #7be1d5;
  font-size: 12px;
  font-weight: 700;
}

.boxPreview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 50px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #11161a;
}

.toolbar button {
  min-width: 38px;
}

#zoomLabel {
  min-width: 52px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stageScroller {
  position: relative;
  overflow: auto;
  padding: 24px;
  background:
    linear-gradient(45deg, #151a1e 25%, transparent 25%),
    linear-gradient(-45deg, #151a1e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #151a1e 75%),
    linear-gradient(-45deg, transparent 75%, #151a1e 75%);
  background-color: #0b0d10;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.stage {
  position: relative;
  width: max-content;
  margin: 0 auto;
  transform-origin: top center;
  background: #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}

#mangaImage {
  display: block;
  max-width: none;
  user-select: none;
}

.stage.empty {
  display: grid;
  place-items: center;
  width: min(620px, calc(100vw - 420px));
  min-height: 420px;
  background: #12171b;
  color: var(--muted);
}

.stage.empty::before {
  content: "Görsel veya ZIP seç";
  font-size: 18px;
  font-weight: 700;
}

.stage.empty #mangaImage,
.stage.empty .overlayLayer {
  display: none;
}

.overlayLayer {
  position: absolute;
  inset: 0;
}

.textBox {
  position: absolute;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(139, 92, 246, 0.85);
  border-radius: 4px;
  cursor: move;
  user-select: none;
}

.textBox.active {
  border: 2px solid var(--accent);
  outline: 2px solid rgba(139, 92, 246, 0.22);
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.textBox .mask {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

.textBox .text {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 11%;
  overflow: hidden;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

.resizeHandle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 13px;
  height: 13px;
  border: 2px solid #0f1418;
  border-radius: 3px;
  background: var(--accent);
  cursor: nwse-resize;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .appHeader {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
  }

  .libraryView {
    padding: 0 12px 14px;
  }

  .libraryHeader {
    align-items: stretch;
    flex-direction: column;
  }

  .libraryActions {
    align-items: stretch;
    flex-direction: column;
  }

  .seriesGrid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .sidebar {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    min-height: 72vh;
  }

  .stageScroller {
    padding: 12px;
  }
}

@media (min-width: 861px) and (max-width: 1180px) {
  .app {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .seriesGrid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}
