/* 日光市 人権イベント WebARフォト A案「かんたん・安心」
   東武ワールドスクウェア Design System トークン準拠 */

:root {
  /* colors */
  --tws-vermillion: #ea5532;
  --tws-vermillion-600: #d8431f;
  --tws-vermillion-700: #bb3616;
  --tws-green: #00a95f;
  --tws-sky: #00afec;
  --tws-ink: #2a3d3d;
  --tws-ink-soft: #37403f;
  --tws-slate: #5c6a68;
  --tws-slate-light: #8a9694;
  --tws-white: #ffffff;
  --tws-cream: #fbf3ec;
  --tws-sky-tint: #eaf7fc;
  --tws-border: #ece2d8;

  --brand-primary: var(--tws-vermillion);
  --brand-primary-press: var(--tws-vermillion-700);
  --text-heading: var(--tws-ink);
  --text-body: var(--tws-ink-soft);
  --text-muted: var(--tws-slate);

  --shadow-brand: 0 8px 20px rgba(234, 85, 50, .28);

  /* type */
  --font-heading: 'Zen Maru Gothic', system-ui, sans-serif;
  --font-body: 'Noto Sans JP', system-ui, sans-serif;

  --radius-pill: 999px;

  --camera-dark: #0f1615;
  --safe-bottom: env(safe-area-inset-bottom, 22px);
  --safe-top: env(safe-area-inset-top, 24px);
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  color: var(--tws-ink);
  letter-spacing: .04em;
  background: var(--camera-dark);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font-family: inherit;
  letter-spacing: inherit;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  color: inherit;
}

@keyframes ar-spin { to { transform: rotate(360deg); } }
@keyframes ar-rise {
  from { transform: translate(-50%, 14px); opacity: 0; }
  to   { transform: translate(-50%, 0);    opacity: 1; }
}

/* ========== 撮影前 ========== */

#screen-camera {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--camera-dark);
}

#screen-camera, #screen-result { scrollbar-width: none; }
#screen-camera::-webkit-scrollbar, #screen-result::-webkit-scrollbar { display: none; }

/* フレームを中央寄せし、撮影操作は画面下部へ固定する。 */
#framing-area {
  position: absolute;
  inset: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#stage {
  position: relative;
  flex: none;
  /* 横幅を基本にし、高さが先に画面へ届く場合は縦に収める。 */
  width: min(100%, calc(100vh * 689 / 988));
  width: min(100%, calc(100dvh * 689 / 988));
  aspect-ratio: 689 / 988;
}

#camera-controls {
  position: absolute;
  inset: auto 0 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 84px 1fr;
  align-items: center;
  gap: 12px;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  pointer-events: none;
}

#camera-controls button { pointer-events: auto; }

#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#cam.mirror { transform: scaleX(-1); }

#frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#camera-status {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, .94);
  border-radius: var(--radius-pill);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--tws-ink);
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .20);
}

#btn-flip {
  justify-self: start;
  width: 104px;
  max-width: 100%;
  min-height: 44px;
  padding: 7px 4px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .94);
  color: var(--tws-ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
  transition: transform 120ms cubic-bezier(.22, .61, .36, 1);
}

#btn-flip:active { transform: scale(.96); }

#btn-shoot {
  grid-column: 2;
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 120ms cubic-bezier(.22, .61, .36, 1);
}

#btn-shoot:active { transform: scale(.96); }
#btn-shoot:disabled { opacity: .55; }

.shutter-circle {
  width: 84px;
  height: 84px;
  border-radius: var(--radius-pill);
  background: var(--brand-primary);
  border: 4px solid rgba(255, 255, 255, .92);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .34);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

/* ========== 撮影後 ========== */

#screen-result {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--tws-cream);
  overflow: hidden;
}

#photo-wrap {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(10px + var(--safe-top)) 12px 12px;
}

#photo {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  height: auto;
  aspect-ratio: 689 / 988;
  object-fit: contain;
  box-shadow: 0 8px 22px rgba(42, 61, 61, .20);
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

#action-sheet {
  flex: none;
  background: #fff;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -6px 24px rgba(42, 61, 61, .10);
  padding: 12px 16px calc(12px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

#action-sheet > :not(#btn-share):not(#btn-save) { grid-column: 1 / -1; }
#action-sheet .btn { min-width: 0; min-height: 48px; font-size: 15px; gap: 6px; }
#action-sheet .btn-ghost { min-height: 36px; }

#photo-status, #save-help {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--tws-slate);
  text-align: center;
}

#photo-status { color: var(--text-heading); }
.btn:disabled { opacity: .55; cursor: default; }

/* ========== ボタン（DS準拠：フルピル） ========== */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  border-radius: var(--radius-pill);
  font-family: var(--font-heading);
  font-weight: 700;
  transition: transform 120ms cubic-bezier(.22, .61, .36, 1), background 120ms;
}

.btn:active { transform: scale(.98); }

.btn-primary {
  min-height: 56px;
  background: var(--brand-primary);
  color: #fff;
  font-size: 17px;
  box-shadow: var(--shadow-brand);
}

.btn-primary:active { background: var(--brand-primary-press); }

.btn-secondary {
  min-height: 52px;
  background: #fff;
  border: 1.5px solid var(--brand-primary);
  color: var(--brand-primary);
  font-size: 16px;
}

.btn-ghost {
  min-height: 46px;
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
}

.btn-ghost:active { background: rgba(42, 61, 61, .06); }

.btn-sm {
  width: auto;
  min-height: 44px;
  padding: 0 22px;
  margin: 14px auto 0;
  font-size: 14px;
}

/* ========== オーバーレイ ========== */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.overlay-loading { background: rgba(251, 243, 236, .93); z-index: 40; }
.overlay-creating { background: rgba(15, 22, 21, .52); z-index: 60; }
.overlay-permission { background: rgba(15, 22, 21, .58); z-index: 50; padding: 24px; }

.spinner {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-pill);
  animation: ar-spin .9s linear infinite;
}

.spinner-dark {
  border: 3px solid rgba(42, 61, 61, .16);
  border-top-color: var(--brand-primary);
}

.spinner-light {
  border: 3px solid rgba(255, 255, 255, .28);
  border-top-color: #fff;
}

.overlay-text {
  font-size: 16px;
  font-weight: 500;
  color: var(--tws-ink-soft);
}

.overlay-text.light { color: #fff; }

.perm-card {
  background: #fff;
  border-radius: 20px;
  padding: 26px 22px;
  width: 300px;
  max-width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(42, 61, 61, .35);
}

.perm-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: var(--radius-pill);
  background: var(--tws-sky-tint);
  color: var(--tws-sky);
  display: flex;
  align-items: center;
  justify-content: center;
}

.perm-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 18px;
  line-height: 1.6;
  color: var(--text-heading);
}

.perm-sub {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--tws-slate);
}

/* ========== 使い方・注意事項 ========== */

#btn-help {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 70;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(42, 61, 61, .2);
  border-radius: 50%;
  color: var(--tws-ink);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
  touch-action: manipulation;
}

#btn-help svg, #btn-help-close svg { display: block; }

#btn-help:focus-visible,
#btn-help-close:focus-visible,
#btn-help-done:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 3px;
}

#help-dialog {
  position: fixed;
  inset: auto 0 0;
  width: min(100%, 520px);
  max-width: 100%;
  max-height: 88vh;
  max-height: 88dvh;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 22px 22px 0 0;
  color: var(--text-body);
  background: #fff;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .34);
  text-align: left;
}

#help-dialog[open] { display: flex; flex-direction: column; }
#help-dialog::backdrop { background: rgba(15, 22, 21, .58); }

.help-header {
  display: flex;
  align-items: center;
  flex: none;
  gap: 12px;
  padding: 14px 14px 14px 22px;
  border-bottom: 1px solid var(--tws-border);
}

.help-header h2 {
  flex: 1;
  margin: 0;
  color: var(--text-heading);
  font-family: var(--font-heading);
  font-size: 18px;
  line-height: 1.5;
}

#btn-help-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--tws-ink);
  background: var(--tws-cream);
}

.help-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 22px 20px;
  font-size: 13px;
  line-height: 1.8;
  touch-action: pan-y;
}

.help-body h3 {
  margin: 18px 0 8px;
  color: var(--text-heading);
  font-family: var(--font-heading);
  font-size: 15px;
  line-height: 1.6;
}

.help-body p { margin: 0 0 10px; }
.help-body ul { margin: 0 0 10px; padding-left: 1.4em; }
.help-body li + li { margin-top: 8px; }
.help-body section:last-child p:last-child { margin-bottom: 0; }

.help-footer {
  flex: none;
  padding: 12px 22px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--tws-border);
}

#btn-help-done { min-height: 44px; }
