:root {
  --bg: #000;
  --panel: #101010;
  --text: #fff;
  --muted: #b7b7b7;
  --line: #555;
  --strong-line: #888;
  --button-bg: #222;
  --button-text: #fff;
  --accent: #fff;
  --error: #fff;
  --header-height: 48px;
}

body[data-theme="white"] {
  --bg: #fff;
  --panel: #fff;
  --text: #111;
  --muted: #555;
  --line: #aaa;
  --strong-line: #333;
  --button-bg: #eee;
  --button-text: #111;
  --accent: #000;
  --error: #900;
}

body[data-theme="contrast"] {
  --bg: #fff;
  --panel: #fff;
  --text: #000;
  --muted: #222;
  --line: #000;
  --strong-line: #000;
  --button-bg: #fff;
  --button-text: #000;
  --accent: #000;
  --error: #000;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  min-height: 40px;
  border: 1px solid var(--strong-line);
  border-radius: 0;
  background: var(--button-bg);
  color: var(--button-text);
  font: inherit;
}

button {
  padding: 6px 12px;
  font-weight: 700;
  cursor: pointer;
}

input,
select {
  width: 100%;
  padding: 6px 8px;
}

a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

.app-header {
  display: flex;
  align-items: flex-start;
  padding: 8px 0 8px 10%;
  border-bottom: 2px solid var(--strong-line);
  background: var(--bg);
  z-index: 10;
}

body[data-sticky="true"] .app-header {
  position: sticky;
  top: 0;
}

.header-content {
  display: flex;
  width: fit-content;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.app-header h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.15;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
}

.settings-button {
  display: flex;
  width: 100%;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 4px 10px;
  font-size: 14px;
}

.icon-button {
  width: 42px;
  min-height: 38px;
  padding: 0;
  font-size: 22px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(150px, 260px) auto 1fr;
  gap: 8px;
  align-items: end;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.toolbar label {
  font-size: 13px;
  font-weight: 700;
}

#status {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.feed-errors {
  margin: 10px 12px;
  padding: 8px;
  border: 2px solid var(--strong-line);
  color: var(--error);
  font-size: 14px;
}

.item-list {
  display: block;
}

.rss-item {
  display: block;
  gap: 14px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  break-inside: avoid;
}

.rss-item.has-image {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
}

.rss-item:focus {
  outline: 3px solid var(--strong-line);
  outline-offset: -3px;
}

.item-image-wrap {
  width: 140px;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--bg);
}

.item-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.item-body {
  min-width: 0;
}

.item-title {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.item-description {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  margin: 0 0 8px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.item-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

body[data-density="compact"] .rss-item.has-image {
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 10px;
  padding: 9px 10px;
}

body[data-density="compact"] .item-image-wrap {
  width: 132px;
}

body[data-density="compact"] .item-title {
  font-size: 17px;
  margin-bottom: 4px;
}

body[data-density="compact"] .item-description {
  font-size: 14px;
  line-height: 1.45;
  margin-bottom: 5px;
}

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

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow-y: auto;
  background: var(--bg);
}

.settings-panel {
  max-width: 900px;
  margin: 0 auto;
  min-height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.settings-header {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 2px solid var(--strong-line);
}

.settings-header h2,
.settings-section h3 {
  margin: 0;
}

.settings-section {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
}

.settings-section h3 {
  margin-bottom: 10px;
  font-size: 17px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.settings-section label {
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 15px !important;
}

.check-row input {
  width: 22px;
  min-height: 22px;
}

.help {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.feed-list {
  margin-top: 8px;
  border-top: 1px solid var(--line);
}

.feed-row {
  display: grid;
  grid-template-columns: 28px minmax(160px, 1fr) minmax(120px, 180px) auto;
  gap: 7px;
  align-items: end;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.feed-row .feed-enabled {
  width: 22px;
  min-height: 22px;
  align-self: center;
}

.feed-url {
  grid-column: 2 / 4;
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.feed-actions {
  display: flex;
  gap: 5px;
}

.feed-actions button {
  min-height: 36px;
}

.add-feed {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) 1fr 1fr auto;
  gap: 7px;
  align-items: end;
  margin-top: 14px;
}

.settings-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 12px 30px;
}

@media (max-width: 700px) {
  .app-header {
    padding-left: 10%;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #status {
    grid-column: 1 / -1;
  }

  .rss-item.has-image,
  body[data-density="compact"] .rss-item.has-image {
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 9px;
  }

  .item-image-wrap,
  body[data-density="compact"] .item-image-wrap {
    width: 104px;
  }

  .item-title {
    font-size: 17px;
  }

  .form-grid,
  .add-feed {
    grid-template-columns: 1fr;
  }

  .feed-row {
    grid-template-columns: 28px minmax(0, 1fr) auto;
  }

  .feed-row .feed-group {
    grid-column: 2 / 3;
  }

  .feed-url {
    grid-column: 2 / 4;
  }
}

@media (max-width: 460px) {
  .rss-item.has-image,
  body[data-density="compact"] .rss-item.has-image {
    display: block;
  }

  .item-image-wrap,
  body[data-density="compact"] .item-image-wrap {
    width: 100%;
    margin-bottom: 9px;
  }
}

@media print {
  .app-header,
  .toolbar,
  .overlay {
    display: none !important;
  }
}
