:root {
  --bg: #141019;
  --bg-2: #1e1826;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.1);
  --text: #f4f1f7;
  --text-dim: #a79fb4;
  --like: #2ee6a8;
  --nope: #ff5c72;
  --hold: #ffc857;
  --accent: #a06bff;
  --radius: 20px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);

  /* マナ・シンボルの色 */
  --mana-w: #f6f0dc;
  --mana-u: #8fc3ee;
  --mana-b: #a99bb0;
  --mana-r: #f0917d;
  --mana-g: #92cba4;
  --mana-c: #cdc7d4;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(160, 107, 255, 0.28), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(46, 230, 168, 0.16), transparent 60%), var(--bg);
  color: var(--text);
  font-family:
    'Hiragino Kaku Gothic ProN',
    'Noto Sans JP',
    'Yu Gothic',
    system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 560px;
  min-height: 100%;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

.screen[hidden] {
  display: none;
}

/* ---------- 見出し ---------- */
.brand {
  text-align: center;
  padding: 12px 0 4px;
}

.brand__title {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0.04em;
  background: linear-gradient(100deg, #fff, var(--accent) 60%, var(--like));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand__lead {
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.7;
}

.brand__lead strong {
  color: var(--text);
}

/* ---------- パネル / フォーム ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(8px);
}

.panel--muted summary {
  cursor: pointer;
  font-size: 14px;
  color: var(--text-dim);
}

.panel--muted[open] summary {
  margin-bottom: 10px;
  color: var(--text);
}

.panel--muted form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field--compact {
  flex: 1;
}

.field__label {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.field__input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

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

.field__input--area {
  resize: vertical;
  font-size: 13px;
  line-height: 1.6;
}

.hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
}

.status {
  margin: 0;
  min-height: 1.2em;
  font-size: 13px;
  text-align: center;
  color: var(--text-dim);
}

.status--error {
  color: var(--nope);
}

/* ---------- ボタン ---------- */
.button {
  padding: 13px 18px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    background 0.2s ease,
    opacity 0.2s ease;
}

.button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.button:active:not(:disabled) {
  transform: scale(0.98);
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

.button--primary {
  background: linear-gradient(100deg, var(--accent), #6b5bff);
  border-color: transparent;
}

.button--small {
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
}

.button--ghost {
  background: transparent;
}

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

.icon-button {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
}

.icon-button[data-mode='off'] {
  opacity: 0.45;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 34vh;
  overflow-y: auto;
}

.saved-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--panel-border);
}

.saved-list__main {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.saved-list__name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-list__meta {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.saved-list__delete {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}

.saved-list__delete:hover {
  color: var(--nope);
  border-color: rgba(255, 92, 114, 0.5);
}

.saved-list__empty {
  justify-content: center;
  color: var(--text-dim);
  font-size: 13px;
}

.save-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.save-row .field__input {
  flex: 1;
  min-width: 0;
}

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

.resume {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
}

.resume__actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

/* ---------- 上部バー ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress {
  flex: 1;
}

.progress__bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.progress__bar span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--like));
  transition: width 0.25s ease;
}

.progress__text {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- カードスタック ---------- */
.deck {
  position: relative;
  flex: 1;
  min-height: 420px;
  touch-action: none;
  user-select: none;
}

.deck__empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  margin: 0;
}

.card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: linear-gradient(170deg, var(--bg-2), #171320);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  overflow: hidden;
  will-change: transform;
  cursor: grab;
}

.card--dragging {
  cursor: grabbing;
}

.card--animating {
  transition:
    transform 0.35s cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 0.35s ease;
}

.card--settling {
  transition: transform 0.32s cubic-bezier(0.18, 0.89, 0.32, 1.18);
}

/* 色に応じた上端のアクセント */
.card__accent {
  height: 4px;
  flex: 0 0 auto;
  background: var(--mana-c);
}

/* 図版。見せ方は .card[data-image] で決める（full = カード全体 / art = イラスト帯 / off = なし） */
.card__image {
  position: relative;
  overflow: hidden;
}

.card__image img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.card__image.is-loaded img {
  opacity: 1;
}

/* 取得できなかったカードは図版ごと畳んで、空の枠を残さない */
.card__image.is-missing,
.card[data-image='off'] .card__image {
  display: none;
}

/* カード全体。画像に残りの高さを全部渡し、日本語の名前とマナだけを下に添える。 */
.card[data-image='full'] .card__image {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 12px 0;
}

/* 切らずに全体を見せる（縦横比はカードによって違う） */
.card[data-image='full'] .card__image img {
  object-fit: contain;
}

.card[data-image='full'] .card__body {
  flex: 0 0 auto;
  gap: 8px;
  padding: 12px 20px 14px;
}

/* タイプとルール・テキストは art / off モードで読む */
.card[data-image='full'] .card__type,
.card[data-image='full'] .card__text {
  display: none;
}

/* イラストのみ。従来どおり上部の帯に切り出して出す。 */
.card[data-image='art'] .card__image {
  flex: 0 0 auto;
  height: 190px;
  background: rgba(0, 0, 0, 0.3);
}

.card[data-image='art'] .card__image img {
  object-fit: cover;
  object-position: center 22%;
}

.card__body {
  flex: 1;
  min-height: 0;
  padding: 18px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.card__head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.card__names {
  flex: 1;
  min-width: 0;
}

.card__name-ja {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.3;
  word-break: break-word;
}

.card__name-en {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-word;
}

.card__mana {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 45%;
}

.mana {
  display: inline-grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: #1b1420;
  background: var(--mana-c);
  white-space: nowrap;
}

.mana--w {
  background: var(--mana-w);
}
.mana--u {
  background: var(--mana-u);
}
.mana--b {
  background: var(--mana-b);
}
.mana--r {
  background: var(--mana-r);
}
.mana--g {
  background: var(--mana-g);
}

.card__type {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 10px;
}

.card__text {
  flex: 1;
  min-height: 0;
  margin: 0;
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* 横スワイプは JS が拾い、縦スクロールはブラウザに任せる */
  touch-action: pan-y;
  color: rgba(244, 241, 247, 0.9);
}

.card__foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.card__stats {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.card__sets {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

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

/* スタンプ */
.stamp {
  position: absolute;
  top: 24px;
  padding: 6px 14px;
  border: 3px solid currentColor;
  border-radius: 10px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
}

.stamp--like {
  left: 20px;
  color: var(--like);
  transform: rotate(-14deg);
}

.stamp--nope {
  right: 20px;
  color: var(--nope);
  transform: rotate(14deg);
}

.stamp--hold {
  left: 50%;
  bottom: 28px;
  top: auto;
  color: var(--hold);
  transform: translateX(-50%);
}

/* ---------- 集計 / 操作 ---------- */
.tally {
  display: flex;
  justify-content: center;
  gap: 18px;
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.tally__item--like b {
  color: var(--like);
}
.tally__item--nope b {
  color: var(--nope);
}
.tally__item--hold b {
  color: var(--hold);
}

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
}

.round-button {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    background 0.2s ease;
}

.round-button:active:not(:disabled) {
  transform: scale(0.93);
}

.round-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.round-button--undo,
.round-button--hold {
  width: 48px;
  height: 48px;
  font-size: 18px;
}

.round-button--like {
  color: var(--like);
  border-color: rgba(46, 230, 168, 0.4);
}
.round-button--nope {
  color: var(--nope);
  border-color: rgba(255, 92, 114, 0.4);
}
.round-button--hold {
  color: var(--hold);
}

.keyhint {
  margin: 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
}

@media (hover: none) {
  .keyhint {
    display: none;
  }
}

/* ---------- 結果 ---------- */
.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.tab.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 46vh;
}

.result-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 14px;
}

.result-list__thumb {
  flex: 0 0 auto;
  width: 62px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
}

.result-list__thumb.is-missing {
  display: none;
}

.result-list__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.result-list__thumb.is-loaded img {
  opacity: 1;
}

.result-list__name {
  flex: 1;
  min-width: 0;
}

.result-list__en {
  font-size: 11px;
  color: var(--text-dim);
  display: block;
}

.result-list__mana {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.result-list__empty {
  justify-content: center;
  color: var(--text-dim);
}

@media (max-width: 380px) {
  .round-button {
    width: 54px;
    height: 54px;
  }
  .deck {
    min-height: 380px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card--animating,
  .card--settling,
  .card__image img,
  .result-list__thumb img,
  .progress__bar span {
    transition-duration: 0.01ms;
  }
}
