:root {
  color-scheme: dark;
  --anthracite: #181818;
  --anthracite-soft: #222222;
  --brand-orange: #e29a2c;
  --brand-pink: #f01b50;
  --brand-gradient: linear-gradient(135deg, var(--brand-orange), var(--brand-pink));
  --bg: #111111;
  --bg-soft: #181818;
  --panel: rgba(34, 34, 34, 0.86);
  --panel-solid: #202020;
  --panel-strong: #282828;
  --ink: #f6f6f6;
  --muted: #a7a7a7;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.16);
  --reader: #202020;
  --reader-ink: #f3f3f3;
  --reader-muted: #c2c2c2;
  --reader-line: rgba(255, 255, 255, 0.12);
  --danger: #ff5c7d;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f5;
  --bg-soft: #ffffff;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --panel-strong: #f0f0f0;
  --ink: #181818;
  --muted: #656565;
  --line: rgba(24, 24, 24, 0.12);
  --line-strong: rgba(24, 24, 24, 0.2);
  --reader: #ffffff;
  --reader-ink: #202020;
  --reader-muted: #5f5f5f;
  --reader-line: rgba(24, 24, 24, 0.12);
  --shadow: 0 24px 70px rgba(24, 24, 24, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(226, 154, 44, 0.2), transparent 34rem),
    radial-gradient(circle at 88% 8%, rgba(240, 27, 80, 0.18), transparent 28rem),
    linear-gradient(145deg, var(--bg), var(--bg-soft));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  display: flex;
  width: 304px;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 24px 18px;
  box-shadow: 18px 0 70px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(22px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #050505;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.brand-mark img {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 18px;
  letter-spacing: 0;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 7px;
  overflow: auto;
  padding-right: 4px;
}

.nav a {
  position: relative;
  display: grid;
  gap: 2px;
  min-height: 54px;
  align-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  padding: 10px 12px 10px 16px;
  text-decoration: none;
}

.nav a::before {
  position: absolute;
  inset: 10px auto 10px 0;
  width: 3px;
  border-radius: 99px;
  background: var(--brand-gradient);
  content: "";
  opacity: 0;
}

.nav a span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav a.active,
.nav a:hover {
  border-color: var(--line);
  background: linear-gradient(135deg, rgba(226, 154, 44, 0.12), rgba(240, 27, 80, 0.12));
}

.nav a.active::before,
.nav a:hover::before {
  opacity: 1;
}

.shell {
  min-height: 100vh;
  padding-left: 304px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-soft) 84%, transparent);
  padding: 16px clamp(18px, 4vw, 52px);
  backdrop-filter: blur(22px);
}

.search-wrap {
  position: relative;
  flex: 1;
}

.search-wrap input,
.penalty-tools input,
.title-input,
.modal input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--ink);
  outline: none;
  padding: 12px 14px;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  z-index: 20;
  max-height: min(560px, 70vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  padding: 8px;
}

.search-results button {
  display: grid;
  width: 100%;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 12px;
  text-align: left;
}

.search-results button:hover {
  border-color: var(--line);
  background: linear-gradient(135deg, rgba(226, 154, 44, 0.12), rgba(240, 27, 80, 0.12));
}

.search-results span,
.search-results p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.search-wrap input::placeholder {
  color: var(--muted);
}

.search-wrap input:focus,
.title-input:focus,
.editor:focus,
.modal input:focus {
  border-color: rgba(240, 27, 80, 0.65);
  box-shadow: 0 0 0 3px rgba(240, 27, 80, 0.18);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  cursor: pointer;
  padding: 0 12px;
}

.theme-toggle-track {
  position: relative;
  width: 42px;
  height: 22px;
  border-radius: 999px;
  background: var(--brand-gradient);
}

.theme-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  transition: transform 180ms ease;
}

:root[data-theme="light"] .theme-toggle-thumb {
  transform: translateX(20px);
}

.hero {
  position: relative;
  padding: 50px clamp(22px, 5vw, 76px) 30px;
}

.hero::after {
  display: block;
  width: min(340px, 72vw);
  height: 4px;
  margin-top: 24px;
  border-radius: 99px;
  background: var(--brand-gradient);
  content: "";
}

.hero h1 {
  max-width: none;
  margin: 0;
  color: var(--ink);
  font-size: clamp(38px, 6vw, 78px);
  font-weight: 900;
  line-height: 0.98;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 20px;
  color: var(--muted);
}

.meta a {
  color: var(--brand-orange);
  font-weight: 800;
}

.reader {
  max-width: none;
  margin: 0 clamp(18px, 5vw, 76px) 80px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--reader);
  box-shadow: var(--shadow);
  color: var(--reader-ink);
  padding: clamp(22px, 4vw, 54px);
}

.penalty-tools {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.penalty-tools input {
  max-width: 520px;
}

.penalty-tools span {
  color: var(--reader-muted);
  white-space: nowrap;
}

.penalty-info {
  position: relative;
  overflow: hidden;
  margin: 0 0 24px;
  border: 1px solid var(--reader-line);
  border-radius: 8px;
  background:
    linear-gradient(var(--reader), var(--reader)) padding-box,
    var(--brand-gradient) border-box;
}

.penalty-info::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--brand-gradient);
  content: "";
}

.penalty-info-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--reader-line);
  padding: 18px 22px 16px 26px;
}

.penalty-info-head p,
.penalty-info-head strong {
  margin: 0;
}

.penalty-info-head p {
  color: var(--brand-orange);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.penalty-info-head strong {
  color: var(--reader-ink);
  font-size: clamp(18px, 2vw, 24px);
}

.penalty-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0;
}

.penalty-info-group {
  min-width: 0;
  padding: 20px 22px 20px 26px;
}

.penalty-info-group + .penalty-info-group {
  border-left: 1px solid var(--reader-line);
}

.penalty-info-group h2 {
  margin: 0 0 12px;
  color: var(--reader-ink);
  font-size: 15px;
}

.penalty-info-group ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.penalty-info-group li {
  position: relative;
  color: var(--reader-muted);
  line-height: 1.45;
  padding-left: 18px;
}

.penalty-info-group li::before {
  position: absolute;
  top: 0.62em;
  left: 0;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--brand-gradient);
  content: "";
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--reader-line);
  border-radius: 8px;
}

.penalty-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  color: var(--reader-ink);
}

.penalty-table th,
.penalty-table td {
  border-bottom: 1px solid var(--reader-line);
  padding: 13px 14px;
  text-align: left;
  vertical-align: top;
}

.penalty-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--reader);
  color: var(--brand-orange);
  font-size: 13px;
  text-transform: uppercase;
}

.penalty-table td {
  color: var(--reader-muted);
}

.penalty-table td:nth-child(3) {
  color: var(--reader-ink);
  font-weight: 750;
}

.search-hit {
  border-radius: 5px;
  background: linear-gradient(135deg, rgba(226, 154, 44, 0.45), rgba(240, 27, 80, 0.38));
  color: var(--reader-ink);
  padding: 0 3px;
}

.search-focus {
  animation: searchPulse 1600ms ease-out 1;
  outline: 2px solid rgba(240, 27, 80, 0.72);
  outline-offset: 4px;
}

.penalty-table tr.search-focus td,
.penalty-info-group li.search-focus {
  background: linear-gradient(135deg, rgba(226, 154, 44, 0.14), rgba(240, 27, 80, 0.14));
}

@keyframes searchPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(240, 27, 80, 0.42);
  }

  100% {
    box-shadow: 0 0 0 16px rgba(240, 27, 80, 0);
  }
}

.reader h1,
.reader h2,
.reader h3 {
  line-height: 1.16;
}

.reader h1 {
  margin: 0 0 28px;
  color: var(--reader-ink);
  font-size: clamp(30px, 4vw, 52px);
  font-weight: 900;
  text-align: center;
}

.reader h2 {
  margin: 38px 0 14px;
  border-top: 1px solid var(--reader-line);
  padding-top: 24px;
  color: var(--reader-ink);
  font-size: 27px;
  font-weight: 850;
}

.reader h3 {
  margin: 24px 0 8px;
  color: var(--brand-orange);
  font-size: 20px;
  font-weight: 850;
}

.reader p,
.reader li {
  color: var(--reader-muted);
  font-size: 17px;
  line-height: 1.72;
}

.primary-button,
.ghost-button,
.icon-button,
.toolbar button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  background: var(--brand-gradient);
  color: #fff;
  padding: 0 18px;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(240, 27, 80, 0.22);
}

.primary-button:hover {
  filter: brightness(1.08);
}

.ghost-button,
.toolbar button {
  border-color: var(--line);
  background: var(--panel-solid);
  color: var(--ink);
  padding: 0 14px;
}

.color-tool,
.select-tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--ink);
  padding: 0 10px;
  font-size: 13px;
}

.color-tool input {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.select-tool select {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 0 6px;
}

.ghost-button:hover,
.toolbar button:hover,
.theme-toggle:hover {
  border-color: var(--line-strong);
  background: var(--panel-strong);
}

.compact {
  min-height: 38px;
}

.icon-button {
  display: none;
  width: 42px;
  background: var(--panel-solid);
  color: var(--ink);
  font-size: 24px;
}

.editor-modal header .icon-button,
.penalty-editor-modal header .icon-button {
  display: grid;
  place-items: center;
}

.modal,
.editor-modal,
.penalty-editor-modal {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 0;
}

.modal::backdrop,
.editor-modal::backdrop,
.penalty-editor-modal::backdrop {
  background: rgba(0, 0, 0, 0.64);
}

.modal form,
.editor-modal form,
.penalty-editor-modal form {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.modal h2,
.editor-modal h2,
.penalty-editor-modal h2 {
  margin: 0;
}

.modal label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.modal menu,
.editor-modal footer,
.editor-modal header,
.penalty-editor-modal footer,
.penalty-editor-modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.editor-modal {
  width: min(1100px, calc(100vw - 28px));
}

.penalty-editor-modal {
  width: min(1500px, calc(100vw - 28px));
}

.editor-modal header p {
  margin: 0 0 4px;
  background: var(--brand-gradient);
  background-clip: text;
  color: transparent;
  font-weight: 900;
  text-transform: uppercase;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-separator {
  width: 1px;
  min-height: 34px;
  background: var(--line);
}

.editor {
  min-height: 50vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  outline: none;
  padding: 22px;
}

.editor img,
.reader img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 18px 0;
}

.editor img.image-left,
.reader img.image-left,
.editor img[data-align="left"],
.reader img[data-align="left"] {
  margin-left: 0;
  margin-right: auto;
}

.editor img.image-center,
.reader img.image-center,
.editor img[data-align="center"],
.reader img[data-align="center"] {
  margin-left: auto;
  margin-right: auto;
}

.editor img.image-right,
.reader img.image-right,
.editor img[data-align="right"],
.reader img[data-align="right"] {
  margin-left: auto;
  margin-right: 0;
}

.editor img.selected-image {
  outline: 3px solid var(--brand-pink);
  outline-offset: 4px;
}

.penalty-editor-actions {
  display: flex;
  justify-content: flex-end;
}

.penalty-edit-wrap {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.penalty-edit-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
}

.penalty-edit-table th,
.penalty-edit-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.penalty-edit-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-solid);
  color: var(--brand-orange);
}

.penalty-edit-table input {
  width: 100%;
  min-width: 110px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 9px;
}

.penalty-edit-table td:nth-child(3) input,
.penalty-edit-table td:nth-child(6) input {
  min-width: 260px;
}

.editor blockquote,
.reader blockquote {
  margin: 18px 0;
  border-left: 4px solid var(--brand-orange);
  padding: 10px 0 10px 16px;
  color: var(--reader-muted);
}

.editor hr,
.reader hr {
  height: 1px;
  border: 0;
  background: var(--reader-line);
  margin: 26px 0;
}

.error {
  color: var(--danger);
}

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .nav-open .sidebar {
    transform: translateX(0);
  }

  .shell {
    padding-left: 0;
  }

  .icon-button {
    display: grid;
    place-items: center;
  }

  .topbar {
    padding: 12px;
  }

  .theme-toggle {
    min-width: 42px;
    padding: 0 9px;
  }

  #themeLabel {
    display: none;
  }

  .hero {
    padding-top: 30px;
  }

  .reader {
    margin-bottom: 36px;
  }

  .penalty-tools,
  .penalty-info-head {
    align-items: stretch;
    flex-direction: column;
  }

  .penalty-tools input {
    max-width: none;
  }

  .penalty-info-group + .penalty-info-group {
    border-top: 1px solid var(--reader-line);
    border-left: 0;
  }
}
