/* Layout: 縦に最大5つのセットカード。各カードは名前の下に小さな写真を横一列。タップで全画面、左右スワイプで前後の写真。 */
:root {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --ink: #0E536D;
  --muted: #1F6078;
  --line: #CBD6DB;
  --green: #0E536D;
  --on-green: #FFFFFF;
  --tone-pink: #F6B7AA;
  --lav: #0E536D;
  --tone-yellow: #FAE06A;
  --tone-blue: #BFE0EE;
  --tile: #EEF3F5;
  --danger: #9A2E2E;
  --danger-soft: #FDEBE7;
  --font-body: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", "Noto Sans", "Segoe UI", Roboto, sans-serif;
  --font-display: "Hiragino Maru Gothic ProN", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", "Noto Sans", "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 18px; line-height: 1.6;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-text-size-adjust: 100%;
}
.wrap { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 3px solid var(--lav); outline-offset: 2px;
}
header { padding: 4px 2px 0; }
h1 { font-family: var(--font-display); font-weight: 700; font-size: 28px; line-height: 1.3; margin: 2px 0 4px; color: var(--green); text-wrap: balance; }
.lead { margin: 0; color: var(--muted); font-size: 16px; }

.btn {
  min-height: 48px; padding: 8px 18px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--green); color: var(--on-green); border-color: var(--green); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger.armed { background: var(--danger); color: var(--surface); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.small { min-height: 44px; padding: 4px 12px; font-size: 16px; }

.set { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.set-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--tone-pink); }
.set.t1 .set-head { background: var(--tone-yellow); }
.set.t2 .set-head { background: var(--tone-blue); }
.set-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mv { display: flex; gap: 6px; margin-right: 4px; }
.btn.icon { min-width: 44px; padding: 0; font-size: 22px; line-height: 1; }
.set-name { min-width: 0; margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 22px; line-height: 1.35; overflow-wrap: anywhere; }
.set-body { padding: 12px 14px 14px; }
.strip { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.thumb {
  position: relative; flex: 0 0 auto; width: 84px; height: 112px; padding: 0; border-radius: 8px;
  border: 1px solid var(--line); background: var(--tile); overflow: hidden;
}
.thumb img { position: absolute; left: 50%; top: 50%; width: 100%; height: 100%; object-fit: contain; display: block; transform: translate(-50%, -50%); }
.thumb img.r90 { width: 133.333%; height: 75%; transform: translate(-50%, -50%) rotate(90deg); }
.thumb img.r180 { transform: translate(-50%, -50%) rotate(180deg); }
.thumb img.r270 { width: 133.333%; height: 75%; transform: translate(-50%, -50%) rotate(270deg); }
.thumb .no {
  position: absolute; right: 4px; bottom: 4px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px;
  background: rgba(20, 28, 23, .72); color: #fff; font-size: 13px; line-height: 22px; text-align: center; font-variant-numeric: tabular-nums;
}
.empty-tile {
  width: 100%; min-height: 96px; border: 2px dashed var(--line); border-radius: 12px; background: transparent;
  color: var(--green); font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px;
}

.edit { display: flex; flex-direction: column; gap: 14px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 15px; color: var(--muted); }
input[type="text"] {
  font: inherit; font-size: 18px; color: var(--ink); background: var(--bg); border: 1.5px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
.grid { display: flex; flex-wrap: wrap; gap: 12px; }
.item { width: 100px; display: flex; flex-direction: column; gap: 6px; }
.item .thumb { width: 100px; height: 132px; }
.item .row { display: flex; gap: 6px; }
.item .row .btn { flex: 1; padding: 0; min-width: 0; }
.item .btn.small { font-size: 14px; }
.edit-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; }
.edit-actions .grow { flex: 1; }

.guide { background: #FAE06A; border: 1px solid #FAE06A; color: var(--ink); border-radius: 16px; padding: 18px 16px; }
.guide h2 { font-family: var(--font-display); font-size: 20px; margin: 0 0 8px; color: var(--green); }
.guide ol { margin: 0 0 14px; padding-left: 1.4em; }
.guide li { margin-bottom: 4px; }
.note { font-size: 15px; color: var(--muted); margin: 0; }
.warn { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-size: 16px; }
.add-area { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }


#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  max-width: min(92vw, 560px); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  font-size: 16px; z-index: 40; text-align: center;
}
#busy {
  position: fixed; inset: 0; z-index: 60; background: rgba(20, 28, 23, .55); display: flex; align-items: center; justify-content: center;
}
#busy div { background: var(--surface); color: var(--ink); padding: 20px 26px; border-radius: 14px; font-weight: 700; text-align: center; }

/* 全画面ビューア(写真の鑑賞用に、どのテーマでも暗い背景) */
#viewer { position: fixed; inset: 0; touch-action: none; z-index: 50; background: #0B2530; color: #F2F5F0; display: flex; flex-direction: column; }
.v-top, .v-tools, .v-dots { position: relative; z-index: 5; flex: none; }
.v-top {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) 10px max(14px, env(safe-area-inset-left, 0px));
}
.v-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.3; }
#vName { font-family: var(--font-display); font-weight: 700; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#vCount { font-size: 15px; color: #B9C6BC; font-variant-numeric: tabular-nums; }
#vMore, #vClose { min-height: 48px; padding: 6px 20px; border-radius: 12px; border: 1.5px solid #4A7385; background: #123846; color: #F2F5F0; font-weight: 700; }
#vStage { position: relative; z-index: 0; contain: paint; isolation: isolate; flex: 1; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#vTrack { display: flex; height: 100%; width: 100%; will-change: transform; }
.v-slide { flex: 0 0 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.v-slide img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; user-select: none; will-change: transform; }
/* ホーム画面のアプリとして開いたとき(特にiPad)は、システムのステータス表示が上に重なるので、少し下げて文字が隠れないようにする */
@media (display-mode: standalone) {
  .v-top { padding-top: calc(22px + env(safe-area-inset-top, 0px)); }
  .v-menu { top: calc(78px + env(safe-area-inset-top, 0px)); }
  #viewer.bare { padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
}
.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 72px; border: 0; border-radius: 12px;
  background: rgba(20, 28, 23, .55); color: #fff; font-size: 30px; line-height: 1; z-index: 2;
}
#vPrev { left: max(6px, env(safe-area-inset-left, 0px)); }
#vNext { right: max(6px, env(safe-area-inset-right, 0px)); }
.v-nav[disabled] { opacity: 0; pointer-events: none; }
.v-tools { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; padding: 10px max(14px, env(safe-area-inset-left, 0px)) 0 max(14px, env(safe-area-inset-right, 0px)); }
.v-tool { flex: 1; max-width: 200px; min-height: 48px; border-radius: 12px; border: 1.5px solid #4A7385; background: #123846; color: #F2F5F0; font-weight: 700; }
.v-dots { display: flex; gap: 8px; justify-content: center; padding: 10px 0 calc(14px + env(safe-area-inset-bottom, 0px)); }
.v-dots i { width: 9px; height: 9px; border-radius: 50%; background: #4A7385; }
.v-dots i.on { background: #F2F5F0; }
#vHint, #vBare {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(20, 28, 23, .8); color: #fff;
  padding: 8px 12px; border-radius: 10px; font-size: 14px; text-align: center; width: max-content; max-width: 96%; z-index: 3; transition: opacity .4s;
}
#vBare { opacity: 0; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { #vHint, #vBare { transition: none; } }
/* 横向き: ボタンを消して全画面。ノッチ・ホームバーは避ける */
#viewer.bare { padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
#viewer.bare .v-top, #viewer.bare .v-tools, #viewer.bare .v-dots, #viewer.bare .v-nav { display: none; }
.sets { display: flex; flex-direction: column; gap: 16px; }
.center { text-align: center; }
.add-tile { flex: 0 0 auto; width: 84px; height: 112px; padding: 0; border: 2px dashed var(--line); border-radius: 8px; background: transparent; color: var(--green); font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.add-tile .plus { font-size: 32px; line-height: 1; }
.add-tile .tc { font-size: 14px; line-height: 1.2; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.add-tile.full { border-style: solid; background: var(--tile); cursor: default; }
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.lang { flex: 0 0 auto; min-height: 44px; padding: 8px 14px; border: 1.5px solid var(--line); border-radius: 12px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; }

#vMore { width: 52px; padding: 6px 0; font-size: 26px; line-height: 1; }
.v-menu { position: absolute; top: calc(66px + env(safe-area-inset-top, 0px)); right: max(14px, env(safe-area-inset-right, 0px)); z-index: 6; min-width: 250px; max-width: calc(100vw - 28px); display: flex; flex-direction: column; gap: 4px; padding: 6px; border: 1.5px solid #4A7385; border-radius: 14px; background: #123846; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); }
.v-menu button { min-height: 50px; padding: 8px 14px; border: 0; border-radius: 10px; background: transparent; color: #F2F5F0; font-weight: 700; font-size: 16px; text-align: left; }
.v-menu button:hover { background: #1B4A5C; }
.v-menu button.del { color: #F4B3B0; }
.v-menu button.armed { background: #9A3434; color: #fff; }

@keyframes setflash { 0% { box-shadow: 0 0 0 0 rgba(14, 83, 109, 0); } 25% { box-shadow: 0 0 0 5px rgba(14, 83, 109, .85); } 100% { box-shadow: 0 0 0 0 rgba(14, 83, 109, 0); } }
.set.flash { animation: setflash 1.2s ease-out; }
@media (prefers-reduced-motion: reduce) { .set.flash { animation: none; outline: 3px solid var(--ink); } }
