/* ===== 色と基本 ===== */
:root {
  --ink: #1a1033;      /* 黒ふち・文字 */
  --purple: #7b2cff;
  --pink: #ff3d8b;
  --orange: #ffb21e;
  --cyan: #2fd8ff;
  --teal: #12c2a4;
  --lime: #d9ff3a;
  --white: #ffffff;
  --gray: #8a8399;
  --star: #ffb21e;
  --grad: linear-gradient(90deg, var(--purple), var(--pink) 55%, var(--orange));
  --round: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", sans-serif;
  --dela: "Dela Gothic One", "M PLUS Rounded 1c", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--round);
  font-weight: 700;
  color: var(--ink);
  background: var(--purple);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* 背景：紫→ピンク→オレンジ＋光＋白い水玉（スクロールしても動かない） */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(rgba(255, 255, 255, .22) 1.6px, transparent 2px) 0 0 / 22px 22px,
    radial-gradient(circle at 10% 90%, rgba(255, 61, 139, .7), transparent 45%),
    radial-gradient(circle at 95% 75%, rgba(47, 216, 255, .6), transparent 40%),
    linear-gradient(150deg, var(--purple), var(--pink) 55%, var(--orange));
}

.wrap {
  max-width: 560px;
  width: 100%;
  flex: 1;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

button, input { font: inherit; color: inherit; }

[hidden] { display: none !important; }

/* ===== ステッカー風の白いカード ===== */
.card {
  background: var(--white);
  border: 4px solid var(--ink);
  border-radius: 24px;
  box-shadow: 8px 8px 0 var(--ink);
  padding: 28px 20px;
}

.pill {
  display: inline-block;
  margin: 0;
  padding: 4px 14px;
  background: var(--ink);
  color: var(--white);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
}

/* ===== ボタン（高さ56px以上・押すと沈む） ===== */
.btn {
  display: block;
  width: 100%;
  min-height: 60px;
  padding: 10px 20px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--ink);
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--ink);
}
.btn:disabled {
  cursor: not-allowed;
  opacity: .5;
}
.btn-main { background: var(--lime); }
.btn-sub { background: var(--white); font-size: 17px; min-height: 56px; }
.btn-x { background: var(--ink); color: var(--white); border-color: var(--ink); box-shadow: 0 6px 0 #000; }
.btn:focus-visible, .chip:focus-visible, .star:focus-visible, .subject:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

/* 画面の下に固定するボタンの帯 */
.bottom-bar {
  position: sticky;
  bottom: 0;
  margin: 20px -16px 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(26, 16, 51, .55) 30%);
}
.counter {
  margin: 0 0 8px;
  text-align: center;
  color: var(--white);
  font-size: 15px;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}

.note {
  margin: 20px 4px 0;
  color: var(--white);
  font-size: 13px;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

/* ===== 1. はじめ ===== */
.hero { text-align: center; padding: 36px 20px 28px; }
.hero-title {
  margin: 18px 0 12px;
  font-family: var(--dela);
  font-weight: 400;
  font-size: clamp(44px, 14vw, 64px);
  line-height: 1.15;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(3px 3px 0 var(--ink));
}
.hero-lead { margin: 0 0 12px; font-size: 16px; }
.hero-lead b { color: var(--pink); font-weight: 800; }
.hero-time {
  display: inline-block;
  margin: 0 0 22px;
  padding: 4px 16px;
  background: var(--lime);
  border: 3px solid var(--ink);
  border-radius: 999px;
  font-size: 18px;
  font-weight: 800;
  transform: rotate(-3deg);
}
.hero .btn + .btn { margin-top: 14px; }

/* ===== 見出し ===== */
.screen-title {
  margin: 0 0 4px;
  font-family: var(--dela);
  font-weight: 400;
  font-size: 26px;
  line-height: 1.3;
  color: var(--white);
  text-shadow: 2px 2px 0 var(--ink);
}
.screen-sub {
  margin: 0 0 16px;
  color: var(--white);
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

/* ===== 2. 科目をえらぶ ===== */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.subject {
  min-height: 64px;
  padding: 6px;
  background: var(--white);
  border: 4px solid var(--ink);
  border-radius: 16px;
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.subject[aria-pressed="true"] {
  background: var(--ink);
  color: var(--lime);
  box-shadow: 2px 2px 0 var(--ink);
  transform: translate(2px, 2px);
}

/* ===== 3. ★をつける ===== */
.filter-label {
  margin: 0 0 6px;
  color: var(--white);
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
.filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.chip {
  min-height: 44px;
  padding: 4px 14px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--lime); }
.chip .count {
  display: inline-block;
  min-width: 1.6em;
  margin-left: 4px;
  padding: 0 5px;
  background: var(--pink);
  color: var(--white);
  border-radius: 999px;
  font-size: 12px;
}

.subject-block + .subject-block { margin-top: 28px; }
.subject-head {
  display: inline-block;
  margin: 0 0 12px;
  padding: 2px 16px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  font-family: var(--dela);
  font-weight: 400;
  font-size: 20px;
}

.book {
  margin-bottom: 12px;
  padding: 14px 14px 10px;
  background: var(--white);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 5px 5px 0 var(--ink);
}
.book.rated { background: #fff8e0; }
.book-title {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.4;
  word-break: break-word;
}
.book-meta {
  margin: 2px 0 6px;
  color: #5d5670;
  font-size: 13px;
  font-weight: 700;
}
.book-meta .tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 8px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink);
}
.stars { display: flex; align-items: center; gap: 2px; }
.star {
  width: 48px;
  height: 48px;
  padding: 0;
  background: none;
  border: 0;
  font-size: 34px;
  line-height: 1;
  color: #d9d4e3;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.star.on {
  color: var(--star);
  text-shadow: 0 0 0 var(--ink), 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink);
}
.book-remove {
  margin-left: auto;
  min-height: 44px;
  padding: 0 10px;
  background: none;
  border: 0;
  color: var(--gray);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}
.add-book {
  width: 100%;
  min-height: 56px;
  background: rgba(255, 255, 255, .85);
  border: 3px dashed var(--ink);
  border-radius: 18px;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}
.btn-back { margin-top: 28px; }

/* 本を追加する入力画面 */
.add-dialog {
  width: min(480px, calc(100% - 32px));
  padding: 22px 18px;
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 8px 8px 0 var(--ink);
}
.add-dialog::backdrop { background: rgba(26, 16, 51, .6); }
.add-title { margin: 0 0 14px; font-size: 20px; font-weight: 800; }
.field { display: block; margin: 0 0 14px; padding: 0; border: 0; font-size: 15px; font-weight: 800; }
.field input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  font-size: 17px; /* 16px以上でiPhoneの自動ズームを防ぐ */
  font-weight: 700;
}
.field legend { padding: 0; margin-bottom: 4px; }
.style-choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.style-choice input { position: absolute; opacity: 0; }
.style-choice span {
  display: block;
  padding: 8px 4px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  text-align: center;
  font-size: 16px;
  cursor: pointer;
}
.style-choice small { display: block; font-size: 11px; font-weight: 700; }
.style-choice input:checked + span { background: var(--ink); color: var(--lime); }
.style-choice input:focus-visible + span { outline: 3px solid var(--cyan); outline-offset: 2px; }
.add-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.add-buttons .btn { min-height: 56px; font-size: 17px; }

/* ===== 4. 結果 ===== */
.result { text-align: center; transform: rotate(-1deg); }
.type-code {
  margin: 14px 0 0;
  font-family: var(--dela);
  font-size: clamp(56px, 19vw, 100px);
  line-height: 1.1;
  letter-spacing: .02em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(4px 4px 0 var(--ink));
}
.type-name {
  margin: 4px 0 18px;
  font-family: var(--dela);
  font-size: clamp(26px, 8vw, 36px);
  line-height: 1.3;
}
.meters { display: grid; gap: 10px; margin: 0 auto 16px; max-width: 420px; text-align: left; }
.meter {
  display: grid;
  grid-template-columns: 4.2em 1fr 4.2em;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
}
.meter .other { color: var(--gray); font-size: 13px; text-align: right; }
.meter .bar {
  height: 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  background: var(--white);
}
.meter .fill { height: 100%; border-radius: 999px; }
.fill.c0 { background: var(--pink); }
.fill.c1 { background: var(--purple); }
.fill.c2 { background: var(--teal); }
.fill.c3 { background: var(--orange); }
.clarity {
  display: inline-block;
  margin: 0 0 16px;
  padding: 6px 16px;
  background: var(--lime);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 16px;
  font-weight: 800;
  transform: rotate(2deg);
}
.type-desc { margin: 0 0 12px; font-size: 15px; text-align: left; }
.type-advice {
  margin: 0;
  padding: 10px 12px;
  background: #f3edff;
  border-radius: 12px;
  font-size: 14px;
  text-align: left;
}
.type-advice span:first-child {
  display: block;
  color: var(--purple);
  font-size: 12px;
  font-weight: 800;
}

.top-title {
  margin: 28px 0 10px;
  font-family: var(--dela);
  font-weight: 400;
  font-size: 22px;
  color: var(--white);
  text-shadow: 2px 2px 0 var(--ink);
}
.top3 { margin: 0; padding: 0; list-style: none; }
.top3 li {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px 14px;
  background: var(--white);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 5px 5px 0 var(--ink);
}
.rank {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: var(--white);
  font-family: var(--dela);
  font-size: 22px;
}
.rank.r1 { background: var(--pink); }
.rank.r2 { background: var(--purple); }
.rank.r3 { background: var(--teal); }
.top-book-title { margin: 0; font-size: 18px; font-weight: 800; line-height: 1.4; word-break: break-word; }
.top-book-meta { margin: 0; color: #5d5670; font-size: 12px; }
.top-book-stars { color: var(--star); font-size: 18px; letter-spacing: 1px; }
.top-book-stars .off { color: #d9d4e3; }

.share { display: grid; gap: 14px; margin-top: 24px; }
.share-status {
  min-height: 1.4em;
  margin: 0;
  color: var(--white);
  font-size: 14px;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}

/* ===== ページの下 ===== */
.footer {
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
  background: rgba(26, 16, 51, .85);
  color: var(--white);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}
.footer p { margin: 0 0 8px; }
.footer a { color: var(--white); min-height: 44px; display: inline-block; padding: 10px; }

/* ===== 保存する画像（1200×675） ===== */
.share-card-holder {
  position: fixed;
  left: -10000px;
  top: 0;
  pointer-events: none;
}
.share-card {
  position: relative;
  width: 1200px;
  height: 675px;
  overflow: hidden;
  font-family: var(--round);
  color: var(--ink);
  background:
    radial-gradient(rgba(255, 255, 255, .22) 2px, transparent 2.5px) 0 0 / 26px 26px,
    radial-gradient(circle at 8% 95%, rgba(255, 61, 139, .75), transparent 40%),
    radial-gradient(circle at 92% 85%, rgba(47, 216, 255, .7), transparent 38%),
    linear-gradient(140deg, var(--purple), var(--pink) 55%, var(--orange));
}
.sc-left {
  position: absolute;
  left: 40px;
  top: 36px;
  width: 490px;
  height: 575px;
  padding: 100px 38px 0;
  background: var(--white);
  border: 5px solid var(--ink);
  border-radius: 28px;
  box-shadow: 10px 10px 0 var(--ink);
  transform: rotate(-1.5deg);
}
.sc-pill {
  display: inline-block;
  margin: 0;
  padding: 6px 18px;
  background: var(--ink);
  color: var(--white);
  border-radius: 999px;
  font-size: 20px;
  font-weight: 800;
}
.sc-code {
  margin: 10px 0 0;
  font-family: var(--dela);
  font-size: 104px;
  line-height: 1.1;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(4px 4px 0 var(--ink));
}
.sc-name {
  margin: 0 0 26px;
  font-family: var(--dela);
  font-size: 48px;
  line-height: 1.2;
  white-space: nowrap;
}
.sc-name.long { font-size: 42px; }
.sc-meters { display: grid; gap: 14px; }
.sc-meters .meter { grid-template-columns: 80px 1fr 80px; gap: 14px; font-size: 19px; }
.sc-meters .meter .other { font-size: 17px; }
.sc-meters .meter .bar { height: 18px; }
.sc-clarity {
  position: absolute;
  right: 40px;
  top: 30px;
  margin: 0;
  padding: 10px 24px;
  background: var(--lime);
  border: 4px solid var(--ink);
  border-radius: 999px;
  box-shadow: 5px 5px 0 var(--ink);
  font-size: 22px;
  font-weight: 800;
  transform: rotate(4deg);
}
.sc-right {
  position: absolute;
  left: 570px;
  right: 40px;
  top: 160px;
}
.sc-top-title {
  margin: 0 0 14px;
  font-family: var(--dela);
  font-size: 30px;
  color: var(--white);
  text-shadow: 2px 2px 0 var(--ink);
}
.sc-top3 { margin: 0; padding: 0; list-style: none; }
.sc-top3 li {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 14px;
  height: 104px;
  margin-bottom: 16px;
  padding: 0 20px;
  background: var(--white);
  border: 5px solid var(--ink);
  border-radius: 20px;
  box-shadow: 7px 7px 0 var(--ink);
}
.sc-top3 .rank { width: 56px; height: 56px; font-size: 28px; border-width: 4px; }
.sc-top3 .top-book-title {
  font-size: 27px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sc-top3 .top-book-title.long { font-size: 22px; }
.sc-top3 .top-book-meta { font-size: 16px; font-weight: 700; }
.sc-top3 .top-book-stars { font-size: 26px; letter-spacing: 0; }
.sc-tag, .sc-url {
  position: absolute;
  bottom: 18px;
  margin: 0;
  color: var(--white);
  font-size: 20px;
  font-weight: 800;
  text-shadow: 0 2px 3px rgba(26, 16, 51, .55);
}
.sc-tag { left: 44px; }
.sc-url { right: 44px; }

/* パソコンの広い画面 */
@media (min-width: 720px) {
  .wrap { padding-top: 48px; }
  .subject-grid { grid-template-columns: repeat(4, 1fr); }
}

/* 動きを減らす設定の人には、押したときの動きも出さない */
@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}

/* Dela Gothic One は太さが1種類だけ。太字を指定すると無理に太らせて文字がつぶれるので、標準の太さにする */
.type-code, .type-name, .rank, .sc-code, .sc-name, .sc-top-title { font-weight: 400; }

/* ★の基準（お気に入り度）の説明 */
.star-guide {
  margin: 0 0 16px;
  padding: 10px 14px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 4px 4px 0 var(--ink);
}
.star-guide-title { margin: 0 0 4px; font-size: 16px; font-weight: 800; }
.star-guide-title b { color: var(--pink); }
.star-guide ul {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}
.star-guide li span { margin-right: 3px; color: #e08f00; font-weight: 800; }

/* タイプのコードと「はっきり度 ○%」は途中で折り返さない（Hや%だけはみ出したり次の行に落ちたりしないように） */
.type-code, .sc-code, .clarity, .sc-clarity { white-space: nowrap; }
