:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #20242b;
  --muted: #68707c;
  --line: #d9dde3;
  --accent: #2f6f5e;
  --accent-weak: #e6f1ed;
  --danger: #b3261e;
  --star: #b7791f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

h1,
h2,
h3 {
  line-height: 1.3;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.ghost {
  background: transparent;
  color: var(--accent);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.series-card:focus-visible {
  outline: 3px solid #83b5a6;
  outline-offset: 2px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0.5rem 0.6rem;
  color: var(--text);
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--danger);
  min-height: 1.5em;
  margin: 0.5rem 0 0;
}

.note {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 1.25rem;
}

/* ログイン */

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2rem;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.35rem;
}

#login-form {
  margin-top: 1.5rem;
}

#login-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

#login-form button {
  width: 100%;
  margin-top: 1rem;
}

/* 一覧 */

#app-view {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.app-header h1 {
  font-size: 1.4rem;
}

.app-header p {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
}

.filters {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) repeat(4, minmax(120px, 1fr));
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem;
  margin-bottom: 1rem;
}

.filters label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.filters label span {
  display: block;
  margin-bottom: 0.25rem;
}

.status {
  min-height: 1.5em;
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.series-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.9rem;
}

.series-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.series-card:hover {
  border-color: #9db8af;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.card-top .average {
  color: var(--star);
  font-weight: 700;
  white-space: nowrap;
}

.card-top .average.empty {
  color: var(--muted);
  font-weight: 400;
}

.series-card h2 {
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
  overflow-wrap: anywhere;
}

.series-card p {
  margin: 0.1rem 0;
  font-size: 0.85rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge[data-status="buy"] {
  color: #1d5c4c;
  background: #dff0ea;
  border-color: #b9dccf;
}

.badge[data-status="watch"] {
  color: #7a5a13;
  background: #fbf0d5;
  border-color: #ecd8a5;
}

.badge[data-status="skip"] {
  color: #5d6470;
  background: #eceef1;
  border-color: #d7dbe1;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.page-info,
#page-info {
  font-size: 0.9rem;
  color: var(--muted);
}

/* 詳細 */

.detail-dialog {
  width: min(900px, 96vw);
  max-height: 92vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.25rem 1.5rem;
  background: var(--panel);
  color: var(--text);
}

.detail-dialog::backdrop {
  background: rgb(20 24 28 / 45%);
}

.dialog-bar {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 0.5rem;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.9rem;
}

.detail-head h2 {
  font-size: 1.35rem;
  overflow-wrap: anywhere;
}

.detail-head .meta {
  color: var(--muted);
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
}

.rating-big {
  color: var(--star);
  font-size: 1.4rem;
  font-weight: 700;
  white-space: nowrap;
  margin: 0;
}

.rating-big span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
  text-align: right;
}

.detail-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  align-items: end;
  margin: 1rem 0 1.25rem;
}

.detail-controls label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.detail-controls label span {
  display: block;
  margin-bottom: 0.25rem;
}

.detail-controls button {
  justify-self: start;
}

.legend {
  font-size: 0.82rem;
  color: var(--muted);
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0 0.75rem;
}

.volume-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.volume-item {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}

.volume-item:last-child {
  border-bottom: 0;
}

.volume-title {
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.volume-title small {
  display: block;
  color: var(--muted);
}

.rating-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.rating-buttons button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
}

.rating-buttons button[aria-pressed="true"] {
  background: var(--accent-weak);
  border-color: var(--accent);
  color: #174c3e;
  font-weight: 700;
}

.rating-buttons button.clear {
  color: var(--muted);
}

.volume-item select {
  width: auto;
  font-size: 0.85rem;
  padding: 0.3rem 0.4rem;
}

.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

/* トースト */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: #20242b;
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  max-width: min(90vw, 560px);
  font-size: 0.9rem;
  z-index: 10;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

@media (max-width: 760px) {
  #app-view {
    padding: 1rem 0.75rem 3rem;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .series-grid {
    grid-template-columns: 1fr;
  }

  .detail-dialog {
    width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    padding: 0.75rem 0.9rem 1.25rem;
  }

  .detail-head {
    flex-direction: column;
  }

  .rating-big span {
    text-align: left;
  }

  .volume-item {
    grid-template-columns: 1fr;
    gap: 0.4rem;
    padding: 0.8rem 0;
  }

  .volume-item select {
    width: 100%;
  }
}
