/* MTGメモメモ - viewer styles */
:root {
  --bg: #f4f2ee;
  --bg-elev: #ffffff;
  --fg: #1f1d1a;
  --fg-muted: #6b665e;
  --border: #d9d4cb;
  --accent: #5a4fcf;
  --accent-fg: #ffffff;
  --chip-bg: #ebe7df;
  --chip-on-bg: #2b2825;
  --chip-on-fg: #ffffff;
  --mana-bg: #d6d2c9;
  --mana-fg: #1f1d1a;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  /* カード画像の表示サイズ（スライダーで JS が上書きする） */
  --card-min: 140px;
  --detail-img-w: clamp(220px, calc(var(--card-min) * 1.75), 480px);
}
@media (min-width: 600px) {
  :root { --card-min: 180px; }
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --bg-elev: #221f26;
    --fg: #ece9e3;
    --fg-muted: #a39d93;
    --border: #3a363f;
    --accent: #9d94ff;
    --accent-fg: #17161a;
    --chip-bg: #2c2931;
    --chip-on-bg: #ece9e3;
    --chip-on-fg: #17161a;
    --mana-bg: #4a4552;
    --mana-fg: #ece9e3;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }

/* header */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 16px 16px 8px;
}
.site-title h1 { margin: 0; font-size: 22px; letter-spacing: 0.02em; }
.site-title h1 a { color: inherit; text-decoration: none; }
.site-sub { margin: 2px 0 0; color: var(--fg-muted); font-size: 13px; }
.set-select select {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--fg);
}

.warnings {
  margin: 0 16px 8px;
  padding: 8px 12px;
  border: 1px solid #d9a441;
  border-radius: 6px;
  background: rgba(217, 164, 65, 0.12);
}
.warnings p { margin: 0; }

/* controls */
.controls {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.control-row:last-child { margin-bottom: 0; }
#q {
  flex: 1 1 220px;
  min-width: 0;
  padding: 8px 10px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--fg);
}
.count { color: var(--fg-muted); font-size: 13px; white-space: nowrap; }
.btn-reset {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  cursor: pointer;
  font-size: 13px;
}
.chip {
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--chip-bg);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
}
.chip[aria-pressed="true"] {
  background: var(--chip-on-bg);
  color: var(--chip-on-fg);
}
.chip:focus-visible, .btn-reset:focus-visible, #q:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chip-legendary { margin-left: 6px; }
.size-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-muted);
  white-space: nowrap;
}
.size-control input[type="range"] {
  width: 120px;
  margin: 0;
  accent-color: var(--accent);
}

/* grid */
main { padding: 12px 16px 24px; }
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--card-min), 100%), 1fr));
  gap: 10px;
}
@media (min-width: 600px) {
  .grid { gap: 12px; }
}
.card[hidden] { display: none; }
.card a { display: block; border-radius: 4.5% / 3.3%; overflow: hidden; box-shadow: var(--shadow); }
.card a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 265 / 370;
  background: var(--chip-bg);
}
.empty { color: var(--fg-muted); text-align: center; padding: 40px 0; }

/* detail dialog */
.detail {
  padding: 0;
  border: none;
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--fg);
  width: min(calc(var(--detail-img-w) + 600px), calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.detail::backdrop { background: rgba(0, 0, 0, 0.55); }
.detail-inner {
  position: relative;
  display: grid;
  grid-template-columns: var(--detail-img-w) 1fr;
  gap: 20px;
  padding: 20px;
}
.detail-image img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 265 / 370;
  border-radius: 4.5% / 3.3%;
  box-shadow: var(--shadow);
}
.detail-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.detail-nav button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}
.detail-pos { color: var(--fg-muted); font-size: 13px; }
.detail-body { min-width: 0; overflow-wrap: anywhere; }
.detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-right: 32px;
}
.detail-head h2 { margin: 0; font-size: 20px; }
.mana { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.mana span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5em;
  height: 1.5em;
  padding: 0 0.3em;
  border-radius: 999px;
  background: var(--mana-bg);
  color: var(--mana-fg);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}
.detail-type { margin: 6px 0 12px; color: var(--fg-muted); }
.detail-pt { margin-left: 8px; color: var(--fg); font-weight: 600; }
.detail-rarity {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--fg-muted);
}
.detail-text { white-space: pre-line; }
.detail-flavor {
  margin-top: 10px;
  padding-left: 10px;
  border-left: 3px solid var(--border);
  color: var(--fg-muted);
  font-style: italic;
  white-space: pre-line;
}
.detail-en { margin-top: 14px; color: var(--fg-muted); font-size: 14px; }
.detail-en summary { cursor: pointer; }
.detail-en .detail-text { margin-top: 6px; }
.detail-prep { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); }
.detail-prep h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--fg-muted); }
.detail-links { margin: 14px 0 0; font-size: 14px; }
.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--chip-bg);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 640px) {
  .detail {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }
  .detail-inner { grid-template-columns: 1fr; gap: 12px; padding: 14px; }
  .detail-image { display: flex; flex-direction: column; align-items: center; }
  .detail-image img { width: min(var(--detail-img-w), 100%); max-height: 60vh; }
  .detail-nav { width: 100%; }
  .detail-head h2 { font-size: 18px; }
}

/* selection */
#select-toggle[aria-pressed="true"] { background: var(--chip-on-bg); color: var(--chip-on-fg); border-color: transparent; }
body.select-mode .card a { cursor: copy; }
.card.selected a { outline: 3px solid var(--accent); outline-offset: 2px; }
.card.selected a::after {
  content: "\2713";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 15px;
  font-weight: 700;
  line-height: 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.card a { position: relative; }
.select-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.12);
  font-size: 14px;
}
.select-bar[hidden] { display: none; }
.select-count { font-weight: 600; margin-right: 4px; }
.select-bar button, .multi-toolbar button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg); /* .multi-toolbar の color: var(--fg-muted) を継承させない（無効に見えるため） */
  cursor: pointer;
  font-size: 13px;
}
.select-bar button:disabled, .multi-toolbar button:disabled { opacity: 0.5; cursor: default; }
#select-open:not(:disabled), #m-copy-image:not(:disabled) { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
body.has-select-bar main { padding-bottom: 80px; }

/* multi-card view */
.multi {
  padding: 0;
  border: none;
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--fg);
  width: min(1100px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.multi::backdrop { background: rgba(0, 0, 0, 0.55); }
.multi-inner { padding: 20px; }
.multi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.multi-head h2 { margin: 0; font-size: 20px; }
.multi-head .detail-close { position: static; }
.multi-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--fg-muted);
}
.multi-toolbar select {
  font: inherit;
  margin-left: 4px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}
.multi-preview { overflow: auto; margin-bottom: 12px; }
#multi-canvas { display: block; max-width: 100%; height: auto; border: 1px solid var(--border); background: #fff; }
.multi-links {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  padding: 8px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}
.multi-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.multi-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.multi-list img { width: 32px; height: auto; border-radius: 3px; }
.multi-list button {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  font-size: 12px;
}
@media (max-width: 640px) {
  .multi { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
  .multi-inner { padding: 14px; }
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--chip-on-bg);
  color: var(--chip-on-fg);
  font-size: 14px;
  box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }
body.has-select-bar .toast { bottom: 90px; }

/* 確認ダイアログ（コピー完了の通知） */
.confirm {
  padding: 20px 24px;
  border: none;
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--fg);
  width: min(360px, calc(100vw - 32px));
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.confirm::backdrop { background: rgba(0, 0, 0, 0.35); }
.confirm-msg { margin: 0 0 16px; font-size: 15px; }
.confirm-actions { display: flex; justify-content: flex-end; }
.confirm-actions button {
  padding: 6px 20px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  font-size: 14px;
}
.confirm-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* footer */
.site-footer {
  padding: 24px 16px 32px;
  border-top: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 12px;
}
.site-footer p { margin: 0 0 6px; }
