/* ===================================================================
 * 漫画更新チェッカー - styles
 * デザイン方針: モバイル優先・タップ領域大きめ・ダーク/ライト両対応
 * =================================================================== */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #94a3b8;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --unread: #ef4444;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --tap-min: 44px;

  --header-h: 56px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.10);

  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", "Meiryo", "Yu Gothic", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #0b1220;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #cbd5e1;
    --text-faint: #64748b;
    --accent: #60a5fa;
    --accent-fg: #0f172a;
    --danger: #f87171;
    --warn: #fbbf24;
    --ok: #4ade80;
    --unread: #f87171;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

/* ---------- Header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 0 10px;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn[disabled] {
  opacity: 0.4;
  pointer-events: none;
}

/* ---------- Main ---------- */

.app-main {
  padding: 12px;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  min-height: var(--tap-min);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.btn:hover {
  background: var(--surface-2);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.btn-primary:hover {
  filter: brightness(0.95);
  background: var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

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

.btn-row .btn {
  flex: 1 1 140px;
  width: auto;
}

/* ---------- Work List ---------- */

.work-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.work-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--text);
  position: relative;
  transition: transform 0.05s ease;
}

.work-card:active {
  transform: scale(0.98);
}

.work-card.is-failed {
  opacity: 0.55;
}

.work-thumb {
  width: 72px;
  height: 96px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-faint);
}

.work-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.work-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.work-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.work-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.work-latest {
  font-size: 13px;
  color: var(--text);
  margin-top: auto;
  padding-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.unread-dot {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--unread);
  box-shadow: 0 0 0 2px var(--surface);
}

.failed-tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--warn);
  border: 1px solid var(--border);
}

/* ---------- Empty / placeholder ---------- */

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty p {
  margin: 8px 0;
}

/* ---------- Detail screen ---------- */

.detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.detail-head {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: start;
}

.detail-thumb {
  width: 96px;
  height: 128px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 11px;
}

.detail-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 6px 0;
  word-break: break-word;
}

.detail-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 0;
  margin: 0;
  list-style: none;
  overflow: hidden;
}

.detail-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.detail-list li:last-child {
  border-bottom: none;
}

.detail-list .key {
  color: var(--text-muted);
  flex-shrink: 0;
}

.detail-list .val {
  text-align: right;
  word-break: break-word;
}

/* ---------- Settings ---------- */

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 14px;
}

.section h2 {
  margin: 0 0 10px 0;
  font-size: 15px;
  font-weight: 700;
}

.section .row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section .row + .row {
  margin-top: 12px;
}

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

.text-field {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  min-height: var(--tap-min);
}

.text-field:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

select.text-field {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

/* ---------- Overlay (loader) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  z-index: 100;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  min-width: 220px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.overlay-text {
  margin: 0 0 10px 0;
  font-weight: 600;
}

.progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.progress::before {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--progress, 0%);
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 14px;
  z-index: 200;
  max-width: calc(100% - 24px);
}

.toast[hidden] {
  display: none;
}

/* ---------- Tier label ---------- */

.tier {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.tier-1 { color: var(--ok); }
.tier-2 { color: var(--warn); }
.tier-3 { color: var(--text-faint); }

/* ---------- Confirm dialog ---------- */

.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  z-index: 150;
}

.confirm {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px;
  width: min(90vw, 360px);
  box-shadow: var(--shadow-md);
}

.confirm h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
}

.confirm p {
  margin: 0 0 16px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.confirm .btn-row .btn {
  flex: 1;
}
