html {
  height: 100%;
}

:root {
  --bg: #f4f1e8;
  --ink: #0f1e28;
  --ink-soft: #45535c;
  --panel: #fffcf5;
  --accent: #d95f3f;
  --accent-strong: #bf4120;
  --line: #dbd4c4;
  --ok: #2b845f;
  --warn: #b1362f;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(20, 33, 44, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  height: 100%;
  color: var(--ink);
  line-height: 1.45;
  font-family: "Space Grotesk", "Avenir Next", Avenir, sans-serif;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 10% 10%, rgba(217, 95, 63, 0.22), transparent 40%),
    radial-gradient(circle at 92% 20%, rgba(28, 124, 97, 0.22), transparent 45%),
    radial-gradient(circle at 60% 100%, rgba(213, 181, 99, 0.2), transparent 45%);
  z-index: -1;
}

h1,
h2,
h3 {
  font-family: "Fraunces", Georgia, serif;
  letter-spacing: 0.01em;
}

.topbar {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: flex-end;
  padding: 1.6rem 1.4rem 1rem;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(4px);
}

.kicker {
  margin: 0;
  font-size: 0.73rem;
  letter-spacing: 0.16em;
  font-weight: 700;
  color: var(--accent-strong);
}

.topbar h1 {
  margin: 0.2rem 0 0;
  font-size: clamp(1.5rem, 2vw + 1rem, 2.2rem);
}

.sync-status {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hamburger-btn {
  display: none;
  align-items: center;
  gap: 0.48rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 86%, white 14%);
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.42rem 0.68rem;
  cursor: pointer;
}

.hamburger-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line) 65%);
}

.hamburger-icon {
  display: grid;
  gap: 3px;
}

.hamburger-icon span {
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.source-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 40, 0.44);
  backdrop-filter: blur(2px);
  z-index: 11;
}

.source-backdrop[hidden] {
  display: none;
}

.workspace {
  padding: 1.2rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(210px, 0.9fr) minmax(280px, 1.1fr) minmax(320px, 2fr);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, white 8%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  padding: 0.9rem 0.95rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--accent-strong);
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: underline;
}

.source-list,
.issue-list {
  list-style: none;
  padding: 0.35rem;
  margin: 0;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  overscroll-behavior: contain;
}

.source-item,
.issue-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  border-radius: 14px;
  color: inherit;
  cursor: pointer;
}

.source-item {
  padding: 0.65rem 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.source-item:hover,
.issue-item:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line) 65%);
  background: color-mix(in srgb, var(--accent) 8%, white 92%);
}

.source-item.active,
.issue-item.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, white 86%);
}

.source-name {
  font-weight: 600;
}

.source-count {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.search-wrap {
  display: block;
  padding: 0.8rem;
  border-bottom: 1px solid var(--line);
}

.search-wrap input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  padding: 0.65rem 0.7rem;
  background: #fffeff;
}

.issue-item {
  padding: 0.75rem;
  margin-bottom: 0.3rem;
}

.issue-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.issue-source {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  font-weight: 700;
}

.issue-date {
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.issue-title {
  margin: 0.4rem 0 0;
  font-size: 1.05rem;
  line-height: 1.15;
}

.reader-head {
  align-items: flex-start;
}

.mobile-back-btn {
  display: none;
}

#readerMeta h2 {
  margin: 0;
  font-size: 1.35rem;
}

#readerMeta p {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.reader-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.reader-content {
  padding: 1rem;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  overscroll-behavior: contain;
}

.reader-content.empty {
  color: var(--ink-soft);
}

.reader-body {
  font-size: 1rem;
  line-height: 1.52;
}

.reader-body img {
  max-width: 100%;
  border-radius: 10px;
}

.btn {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 0.55rem 0.75rem;
  font-size: 0.84rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.btn:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line) 55%);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: color-mix(in srgb, var(--accent) 78%, black 22%);
}

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

.btn-danger {
  background: color-mix(in srgb, var(--warn) 12%, white 88%);
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--line) 65%);
}

.modal {
  border: none;
  border-radius: 16px;
  max-width: 640px;
  width: min(92vw, 640px);
  box-shadow: 0 24px 80px rgba(15, 30, 40, 0.35);
  padding: 0;
}

.modal::backdrop {
  background: rgba(12, 20, 28, 0.4);
}

.modal-form {
  display: grid;
  gap: 0.72rem;
  padding: 1rem;
}

.modal-form header h3 {
  margin: 0;
  font-size: 1.28rem;
}

.modal-form header p {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
}

.modal-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.84rem;
  font-weight: 600;
}

.modal-form input,
.modal-form textarea,
.modal-form select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.58rem 0.62rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.3rem;
}

.reveal {
  animation: enter 460ms cubic-bezier(0.3, 0.65, 0.3, 1) both;
}

.reveal:nth-child(2) {
  animation-delay: 90ms;
}

.reveal:nth-child(3) {
  animation-delay: 180ms;
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.99);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1080px) {
  body {
    overflow-y: auto;
    overflow-x: hidden;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: 0;
    overflow: auto;
  }

  .panel {
    min-height: 260px;
  }

  .panel-reader {
    min-height: 420px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }
}

@media (max-width: 700px) {
  body.mobile-source-open {
    overflow: hidden;
  }

  body.mobile-reader-open {
    overflow: hidden;
  }

  body.mobile-reader-open .topbar {
    display: none;
  }

  .topbar {
    padding: 1.1rem 1rem 0.75rem;
    gap: 0.65rem;
    align-items: flex-start;
  }

  .hamburger-btn {
    display: inline-flex;
  }

  .topbar h1 {
    font-size: clamp(1.35rem, 5.2vw, 1.75rem);
    line-height: 1.15;
  }

  .sync-status {
    font-size: 0.88rem;
    line-height: 1.35;
  }

  .toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .toolbar .btn {
    width: 100%;
    min-height: 42px;
    text-align: center;
  }

  .workspace {
    padding: 0.8rem;
    gap: 0.8rem;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    align-content: start;
  }

  .panel-head {
    padding: 0.62rem 0.72rem;
  }

  .panel-head h2 {
    font-size: 1.05rem;
  }

  .panel-sources {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    height: 100dvh;
    z-index: 12;
    border-radius: 0 16px 16px 0;
    transform: translateX(-110%);
    transition: transform 220ms ease;
    min-height: 100dvh;
    animation: none;
    pointer-events: none;
  }

  .panel-sources.open {
    transform: translateX(0);
    pointer-events: auto;
  }

  .panel-sources .panel-head {
    position: sticky;
    top: 0;
    z-index: 1;
    background: color-mix(in srgb, var(--panel) 92%, white 8%);
  }

  .panel-issues {
    height: 100%;
    min-height: 0;
  }

  .panel-reader {
    display: none;
    height: 100%;
    min-height: 0;
  }

  body.mobile-reader-open .workspace {
    padding: 0;
  }

  body.mobile-reader-open .panel-issues {
    display: none;
  }

  body.mobile-reader-open .panel-reader {
    display: flex;
    border-radius: 0;
    border-inline: none;
    border-top: none;
    box-shadow: none;
  }

  .source-list {
    display: block;
    padding: 0.6rem;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .source-list li {
    margin-bottom: 0.35rem;
  }

  .source-item {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    gap: 0.45rem;
    padding: 0.62rem 0.68rem;
  }

  .source-name {
    font-size: 0.88rem;
  }

  .source-count {
    font-size: 0.78rem;
  }

  .search-wrap {
    padding: 0.52rem 0.58rem;
  }

  .search-wrap input {
    font-size: 0.92rem;
    padding: 0.48rem 0.56rem;
  }

  .issue-item {
    border-radius: 10px;
    margin-bottom: 0.18rem;
    padding: 0.52rem 0.58rem;
  }

  .issue-source {
    font-size: 0.66rem;
    letter-spacing: 0.07em;
  }

  .issue-date {
    flex: 0 0 auto;
    font-size: 0.72rem;
  }

  .issue-title {
    font-size: 0.92rem;
    line-height: 1.18;
    margin-top: 0.22rem;
  }

  .reader-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.55rem;
    position: sticky;
    top: 0;
    z-index: 1;
    background: color-mix(in srgb, var(--panel) 94%, white 6%);
  }

  .mobile-back-btn {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.4rem 0.52rem;
    cursor: pointer;
  }

  #readerMeta {
    min-width: 0;
  }

  #readerMeta h2 {
    font-size: 1.02rem;
    line-height: 1.25;
  }

  #readerMeta p {
    font-size: 0.78rem;
    line-height: 1.35;
  }

  .reader-actions {
    flex-wrap: nowrap;
  }

  .reader-actions .btn {
    min-height: 36px;
    padding: 0.4rem 0.52rem;
  }

  .reader-content {
    padding: 0.78rem;
    overflow-x: hidden;
  }

  .reader-body {
    font-size: 1.02rem;
    line-height: 1.62;
    max-width: 100%;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .reader-body * {
    box-sizing: border-box;
    max-width: 100% !important;
  }

  .reader-body [style*="min-width"] {
    min-width: 0 !important;
  }

  .reader-body table[style*="width"],
  .reader-body table[width],
  .reader-body img[style*="width"],
  .reader-body img[width],
  .reader-body div[style*="width"],
  .reader-body div[width],
  .reader-body section[style*="width"],
  .reader-body section[width],
  .reader-body article[style*="width"],
  .reader-body article[width] {
    width: 100% !important;
    max-width: 100% !important;
  }

  .reader-body table {
    display: table;
    table-layout: fixed;
    width: 100% !important;
  }

  .reader-body td,
  .reader-body th {
    word-break: break-word;
  }

  .reader-body a {
    overflow-wrap: anywhere;
  }

  .reader-body pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
}
