:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --text: #0c1420;
  --sub: #4a5565;
  --line: #d5dae2;
  --accent: #0b5cd6;
  --danger: #c2261d;
  --bar: #0f1b2d;
  --bar-text: #ffffff;
  --shadow: 0 2px 8px rgba(12, 20, 32, .16);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f17;
    --panel: #18212e;
    --text: #f3f6fa;
    --sub: #b4bfcd;
    --line: #2c3848;
    --accent: #6fb0ff;
    --danger: #ff8a80;
    --bar: #05090f;
    --shadow: 0 2px 8px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bar); color: var(--bar-text);
}
.bar-main { flex: 1; min-width: 0; }
.bar h1 { margin: 0; font-size: 20px; font-weight: 700; }
.status { margin: 2px 0 0; font-size: 13px; opacity: .85; min-height: 18px; }
.icon-btn {
  width: 48px; height: 48px; border: 0; border-radius: 24px;
  background: transparent; color: inherit; font-size: 24px; line-height: 1;
}
.icon-btn:active { background: rgba(255, 255, 255, .18); }

.menu {
  position: fixed; z-index: 6; right: 12px; top: calc(env(safe-area-inset-top) + 64px);
  display: flex; flex-direction: column; min-width: 260px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
.menu[hidden] { display: none; }
.menu button {
  min-height: 56px; padding: 0 18px; text-align: left;
  background: transparent; border: 0; border-bottom: 1px solid var(--line);
}
.menu button:last-child { border-bottom: 0; }
.menu .danger { color: var(--danger); }

.notice {
  margin: 12px 16px 0; padding: 12px 14px; border-radius: 12px;
  background: var(--panel); border: 2px solid var(--accent); font-size: 15px;
}
.notice button {
  margin-top: 8px; min-height: 44px; padding: 0 18px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .notice button, .primary { color: #05090f !important; } }

main { padding: 4px 16px calc(env(safe-area-inset-bottom) + 28px); max-width: 1100px; margin: 0 auto; }
.section-title {
  margin: 22px 2px 10px; font-size: 15px; font-weight: 700; color: var(--sub);
  display: flex; align-items: baseline; gap: 8px;
}
.section-title small { font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; padding: 0; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer;
}
.card:active { transform: scale(.98); }
.thumb {
  position: relative; aspect-ratio: 1.586; width: 100%; background: #dfe4ea; overflow: hidden;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.card-title {
  padding: 9px 10px 11px; font-size: 15px; font-weight: 700; line-height: 1.3;
  min-height: 60px; word-break: break-all;
}
.card-title small { display: block; margin-top: 2px; font-size: 12px; font-weight: 400; color: var(--sub); }
.empty { margin: 48px 8px; text-align: center; color: var(--sub); }

.welcome { padding: 18vh 28px 0; text-align: center; }
.welcome img { border-radius: 22px; }
.welcome h2 { margin: 14px 0 8px; font-size: 24px; }
.welcome p { color: var(--sub); white-space: pre-line; }
.primary {
  margin-top: 18px; min-width: 220px; min-height: 56px; border: 0; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 18px; font-weight: 700;
}

.viewer {
  position: fixed; inset: 0; z-index: 10; background: #000; color: #fff;
  display: flex; flex-direction: column;
}
.viewer[hidden] { display: none; }
.viewer-top {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px 16px; font-weight: 700; font-size: 16px;
}
.viewer-top span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage {
  flex: 1; min-height: 0; overflow: hidden; touch-action: none;
  display: flex; align-items: center; justify-content: center;
}
.stage img {
  max-width: 100%; max-height: 100%; background: #fff;
  transform-origin: center; will-change: transform; user-select: none; -webkit-user-drag: none;
}
.face-nav {
  display: flex; justify-content: center; gap: 10px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 14px); min-height: 72px;
}
.face-nav button {
  min-width: 84px; min-height: 48px; padding: 0 16px; border-radius: 24px;
  border: 2px solid #8a94a3; background: transparent; color: #fff; font-weight: 700;
}
.face-nav button[aria-current="true"] { background: #fff; color: #000; border-color: #fff; }
