@import url('https://fonts.googleapis.com/css2?family=Zen+Maru+Gothic:wght@400;500;700;900&family=M+PLUS+Rounded+1c:wght@400;500;700;800&display=swap');

:root {
  --sky: #87CEEB;
  --sky-deep: #5EB8DE;
  --pink: #FFB6D9;
  --pink-deep: #FF8FC7;
  --lavender: #D9C5F5;
  --mint: #B8F2E0;
  --yellow: #FFE29A;
  --cream: #FFF9F2;
  --text: #5A5470;
  --text-soft: #8B85A0;
  --white: #ffffff;
  --shadow: 0 4px 14px rgba(120, 110, 160, 0.15);
  --shadow-soft: 0 2px 8px rgba(120, 110, 160, 0.10);
  --radius: 20px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: 'M PLUS Rounded 1c', 'Zen Maru Gothic', sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #EAF6FC 0%, #FDF3FA 100%);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
  width: 100%;
}

button { font-family: inherit; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: transparent;
  overflow-x: hidden;
  width: 100%;
}

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px calc(10px + env(safe-area-inset-top, 0px));
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: linear-gradient(135deg, var(--sky) 0%, var(--sky-deep) 100%);
  color: white;
  box-shadow: var(--shadow-soft);
}
.topbar h1 {
  font-size: 18px; margin: 0; font-weight: 800; flex: 1;
  display: flex; align-items: center; gap: 6px;
}
.topbar .back-btn, .topbar .icon-btn {
  background: rgba(255,255,255,0.28);
  border: none; color: white;
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 18px; display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

.view { flex: 1; padding: 16px; padding-bottom: 100px; }

/* ---------- Home ---------- */
.section-title {
  font-size: 14px; font-weight: 800; color: var(--text-soft);
  margin: 18px 4px 10px; display: flex; align-items: center; gap: 6px;
}
.section-title .icon-ui { width: 20px; height: 20px; object-fit: contain; }
.menu-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
  margin-bottom: 4px;
}
.menu-item {
  background: var(--white); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 12px 4px; cursor: pointer; border: none;
  aspect-ratio: 1 / 1;
  min-width: 0; width: 100%;
  overflow: hidden;
}
.menu-item .emoji { font-size: 26px; }
.menu-item .emoji-icon { width: 34px; height: 34px; object-fit: contain; max-width: 100%; }
.menu-item span.label { font-size: 11px; font-weight: 700; color: var(--text); text-align: center; max-width: 100%; }

.fav-scroll {
  display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 10px;
  scroll-snap-type: x proximity;
}
.fav-card {
  flex: 0 0 auto; width: 110px; cursor: pointer; scroll-snap-align: start;
}
.fav-card .thumb {
  width: 110px; height: 146px; border-radius: var(--radius-sm);
  background-size: cover; background-position: center;
  box-shadow: var(--shadow-soft); position: relative; overflow: hidden;
  background-color: #fff;
}
.fav-card .thumb .star { position: absolute; top: 4px; right: 4px; font-size: 16px; }
.fav-card p { font-size: 11px; text-align: center; margin: 6px 0 0; color: var(--text-soft); }

.empty-hint {
  text-align: center; color: var(--text-soft); font-size: 13px;
  padding: 24px 10px; background: rgba(255,255,255,0.6); border-radius: var(--radius-sm);
}

.book-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px;
}
.book-card { cursor: pointer; min-width: 0; }
.book-card .cover {
  width: 100%; aspect-ratio: 3/4.2; border-radius: 10px;
  background-size: cover; background-position: center; background-color: #fff;
  box-shadow: var(--shadow-soft); border: 1px solid rgba(255,255,255,0.6);
}
.book-card p { font-size: 11px; text-align: center; margin: 6px 2px 0; color: var(--text); font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-card .new-book { display: flex; align-items: center; justify-content: center; color: var(--sky-deep);
  font-size: 30px; border: 2px dashed var(--sky); background: rgba(255,255,255,0.5); }

.fab {
  position: fixed; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); right: 50%; transform: translateX(240px);
  background: linear-gradient(135deg, var(--pink) 0%, var(--pink-deep) 100%);
  color: white; border: none; border-radius: 50%;
  width: 56px; height: 56px; font-size: 26px; box-shadow: var(--shadow);
  cursor: pointer; z-index: 20;
}
@media (max-width: 600px) {
  .fab { right: 24px; transform: none; }
}

/* ---------- Gacha ---------- */
.gacha-view { display: flex; flex-direction: column; align-items: center; padding-top: 10px; }
.gacha-machine-wrap { width: min(72vw, 300px); margin: 10px auto 6px; position: relative; }
.gacha-machine-wrap img { width: 100%; display: block; filter: drop-shadow(0 8px 16px rgba(120,110,160,0.25)); }
.gacha-machine-wrap.spin { animation: gachaShake 0.6s ease; }
@keyframes gachaShake {
  0%,100% { transform: rotate(0deg); }
  20% { transform: rotate(-4deg); }
  40% { transform: rotate(4deg); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(3deg); }
}
.gacha-btn {
  margin-top: 10px; background: linear-gradient(135deg, var(--pink) 0%, var(--pink-deep) 100%);
  color: white; border: none; padding: 14px 40px; border-radius: 30px;
  font-size: 17px; font-weight: 800; box-shadow: var(--shadow); cursor: pointer;
}
.gacha-btn:disabled { opacity: 0.6; }
.gacha-sub { margin-top: 24px; text-align: center; }
.gacha-sub a.link-btn {
  display: inline-block; margin-top: 6px; background: var(--white); color: var(--sky-deep);
  padding: 10px 20px; border-radius: 20px; font-weight: 700; font-size: 13px;
  box-shadow: var(--shadow-soft); text-decoration: none; cursor: pointer;
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(90, 84, 112, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal-card {
  background: linear-gradient(180deg, #fff 0%, #FFF6FB 100%);
  border-radius: 24px; padding: 26px 22px; text-align: center;
  max-width: 320px; width: 100%; box-shadow: var(--shadow);
  animation: popIn 0.25s cubic-bezier(.2,1.4,.4,1);
}
@keyframes popIn { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-card .badge {
  display: inline-block; font-size: 13px; font-weight: 900; padding: 4px 14px;
  border-radius: 14px; margin-bottom: 10px;
}
.modal-card .badge.new { background: var(--yellow); color: #9a6b00; }
.modal-card .badge.dup { background: var(--mint); color: #2c7d67; }
.modal-card .result-img {
  width: 150px; height: 150px; object-fit: contain; margin: 0 auto 12px;
  background: #fff; border-radius: 16px; box-shadow: var(--shadow-soft);
}
.modal-card .count-txt { font-size: 13px; color: var(--text-soft); margin-bottom: 16px; }
.modal-card .actions { display: flex; gap: 10px; justify-content: center; }
.modal-card button.primary {
  background: linear-gradient(135deg, var(--sky) 0%, var(--sky-deep) 100%);
  color: white; border: none; padding: 10px 22px; border-radius: 20px; font-weight: 700; cursor: pointer;
}
.modal-card button.secondary {
  background: var(--white); color: var(--text-soft); border: 1px solid #eee;
  padding: 10px 18px; border-radius: 20px; font-weight: 700; cursor: pointer;
}

/* ---------- Zukan ---------- */
.zukan-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.zukan-cell {
  aspect-ratio: 1/1; background: var(--white); border-radius: 14px;
  box-shadow: var(--shadow-soft); position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.zukan-cell img { width: 78%; height: 78%; object-fit: contain; }
.zukan-cell.locked { background: #EDEBF3; }
.zukan-cell.locked .q { font-size: 22px; color: #C6C1D6; font-weight: 900; }
.zukan-cell .count {
  position: absolute; bottom: 3px; right: 5px; font-size: 10px; font-weight: 800;
  color: var(--sky-deep); background: rgba(255,255,255,0.85); border-radius: 8px; padding: 1px 6px;
}
.zukan-progress { text-align: center; font-size: 13px; color: var(--text-soft); margin-bottom: 14px; font-weight: 700; }

/* ---------- Maker ---------- */
.maker-view { text-align: center; }
.maker-drop {
  border: 2px dashed var(--sky); border-radius: var(--radius); padding: 30px 16px;
  background: rgba(255,255,255,0.6); margin-bottom: 16px; cursor: pointer;
}
.maker-drop p { color: var(--text-soft); font-size: 13px; margin: 8px 0 0; }
.maker-preview-wrap {
  width: 220px; height: 220px; margin: 0 auto 16px; background: repeating-conic-gradient(#f0f0f5 0% 25%, #fff 0% 50%) 50%/16px 16px;
  border-radius: 16px; display: flex; align-items: center; justify-content: center; overflow: hidden;
  box-shadow: var(--shadow-soft);
}
.maker-preview-wrap canvas { max-width: 100%; max-height: 100%; }
.maker-options { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 18px; font-size: 14px; font-weight: 700; }
.toggle-switch { width: 46px; height: 26px; background: #ddd; border-radius: 14px; position: relative; cursor: pointer; transition: background 0.2s; border: none; }
.toggle-switch.on { background: var(--sky); }
.toggle-switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: white; border-radius: 50%; transition: left 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle-switch.on .knob { left: 23px; }
.maker-save-btn {
  background: linear-gradient(135deg, var(--mint) 0%, #7FD9BE 100%); color: #205C4A;
  border: none; padding: 13px 36px; border-radius: 26px; font-weight: 800; font-size: 15px; cursor: pointer; box-shadow: var(--shadow-soft);
}
.maker-save-btn:disabled { opacity: 0.5; }

/* ---------- Book create modal ---------- */
.picker-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 10px 0 4px; }
.picker-row.covers { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.picker-row .pick {
  border-radius: 10px; overflow: hidden; aspect-ratio: 3/4; background-size: cover; background-position: center;
  border: 3px solid transparent; cursor: pointer; background-color: #fff;
}
.picker-row.bgs .pick { aspect-ratio: 1/1.1; }
.picker-row .pick.selected { border-color: var(--pink-deep); }
.field-label { font-size: 12px; font-weight: 800; color: var(--text-soft); margin: 14px 0 4px; text-align: left; }
.text-input {
  width: 100%; padding: 11px 14px; border-radius: 14px; border: 1.5px solid #eadff0;
  font-size: 14px; font-family: inherit; background: #fff;
}
.modal-card.wide { max-width: 380px; text-align: left; max-height: 86vh; overflow-y: auto; }

/* ---------- Book viewer/editor ---------- */
.book-view-wrap { display: flex; flex-direction: column; align-items: center; }
.page-stage {
  width: 100%; max-width: 420px; aspect-ratio: 3/4; position: relative;
  border-radius: 16px; overflow: hidden; box-shadow: var(--shadow);
  background-size: cover; background-position: center; background-color: #fff;
  touch-action: none;
}
.placed-sticker {
  position: absolute; width: 100px; height: 100px; left: 0; top: 0;
  transform-origin: center center; touch-action: none; cursor: grab;
}
.placed-sticker img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.placed-sticker.selected::after {
  content: ''; position: absolute; inset: -6px; border: 2px dashed var(--pink-deep); border-radius: 10px;
}
.page-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 14px; }
.page-nav button { background: var(--white); border: none; width: 40px; height: 40px; border-radius: 50%;
  box-shadow: var(--shadow-soft); font-size: 18px; color: var(--sky-deep); cursor: pointer; }
.page-nav .page-dots { font-size: 13px; font-weight: 800; color: var(--text-soft); min-width: 60px; text-align: center; }

.book-toolbar { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.book-toolbar button {
  background: var(--white); border: none; padding: 9px 16px; border-radius: 20px;
  font-size: 12.5px; font-weight: 700; color: var(--text); box-shadow: var(--shadow-soft); cursor: pointer;
  display: flex; align-items: center; gap: 5px;
}
.book-toolbar button.active { background: linear-gradient(135deg, var(--sky) 0%, var(--sky-deep) 100%); color: white; }
.book-toolbar button.danger { color: #E0678A; }

.sticker-tray {
  margin-top: 16px; width: 100%; max-width: 420px;
}
.sticker-tray .tray-grid {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px;
  max-height: 220px; overflow-y: auto; padding: 10px; background: rgba(255,255,255,0.7); border-radius: 16px;
}
.sticker-tray .tray-item {
  aspect-ratio: 1/1; background: white; border-radius: 10px; box-shadow: var(--shadow-soft);
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 4px;
}
.sticker-tray .tray-item img { width: 100%; height: 100%; object-fit: contain; }

.select-toolbar {
  display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap;
}
.select-toolbar button {
  background: var(--white); border: none; width: 38px; height: 38px; border-radius: 50%;
  box-shadow: var(--shadow-soft); font-size: 15px; cursor: pointer; color: var(--text);
}
.select-toolbar button.danger { color: #E0678A; }

.adjust-row {
  display: flex; gap: 18px; justify-content: center; align-items: center; flex-wrap: wrap;
  margin-top: 12px; background: rgba(255,255,255,0.7); border-radius: 16px; padding: 10px 16px;
}
.adjust-row label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.adjust-row input[type="range"] { width: 120px; accent-color: var(--pink-deep); }

.bg-sheet { position: fixed; inset: 0; background: rgba(90,84,112,0.4); z-index: 90; display: flex; align-items: flex-end; }
.bg-sheet .sheet-inner { background: white; width: 100%; border-radius: 22px 22px 0 0; padding: 20px; max-height: 70vh; overflow-y: auto; }

.title-row { display: flex; align-items: center; gap: 8px; justify-content: center; margin-top: 4px; }
.title-row h2 { font-size: 16px; margin: 0; font-weight: 800; }
.title-row .star-btn { background: none; border: none; font-size: 20px; cursor: pointer; }

.tabbar {
  position: sticky; bottom: 0; z-index: 25; display: flex; background: white;
  box-shadow: 0 -2px 10px rgba(120,110,160,0.12);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar button {
  flex: 1; border: none; background: none; padding: 10px 4px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-soft); font-size: 10px; font-weight: 700;
}
.tabbar button .emoji { font-size: 19px; }
.tabbar button .tab-icon { width: 21px; height: 21px; object-fit: contain; }
.tabbar button.active { color: var(--sky-deep); }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(90,84,112,0.9); color: white; padding: 10px 20px; border-radius: 20px;
  font-size: 13px; z-index: 200; font-weight: 700; box-shadow: var(--shadow);
}

.settings-list { background: white; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-soft); }
.settings-list button, .settings-list label {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 15px 16px; border: none;
  background: none; text-align: left; font-size: 14px; font-weight: 700; color: var(--text);
  border-bottom: 1px solid #f4f1f8; cursor: pointer;
}
.settings-list button:last-child, .settings-list label:last-child { border-bottom: none; }
