/* theme/theme.css
   Shared theming layer for:
   - AI Call (visitor UI)
   - Manage (receiver UI)

   Goals:
   - Background image per location (Hakone/Kamakura/etc.)
   - Center stays clean: background is strong at edges and fades toward center
   - Support dark/light tone switching
   - Small header menu for sales demo
*/

:root{
  /* Theme background image layer (optional) */
  --theme-bg-image: none;
  --theme-bg-opacity: 0;
  --theme-bg-size: cover;
  --theme-bg-position: center;
  --theme-bg-repeat: no-repeat;
  --theme-bg-filter: none;

  /* Make the bg image strong at edges, weak at center */
  --theme-bg-mask:
    radial-gradient(circle at 50% 48%,
      rgba(0,0,0,0) 0%,
      rgba(0,0,0,0) 38%,
      rgba(0,0,0,1) 78%,
      rgba(0,0,0,1) 100%);
}

/* Background image layer (works for both apps)
   - z-index: 0 (behind main UI)
   - sits ABOVE the body's own background, but BELOW the app content
*/
body::before{
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;

  background-image: var(--theme-bg-image);
  background-size: var(--theme-bg-size);
  background-position: var(--theme-bg-position);
  background-repeat: var(--theme-bg-repeat);

  opacity: var(--theme-bg-opacity);
  filter: var(--theme-bg-filter);

  /* Fade center to protect the main answer area */
  -webkit-mask-image: var(--theme-bg-mask);
  mask-image: var(--theme-bg-mask);

  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;

  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

/* ============================
   Mobile overrides for theme bg
   - Optional per-theme vars:
     --theme-bg-image-mobile
     --theme-bg-size-mobile
     --theme-bg-position-mobile
     --theme-bg-repeat-mobile
     --theme-bg-opacity-mobile
     --theme-bg-filter-mobile
     --theme-bg-mask-mobile
   ============================ */
@media (max-width: 520px){
  body::before{
    background-image: var(--theme-bg-image-mobile, var(--theme-bg-image));
    background-size: var(--theme-bg-size-mobile, var(--theme-bg-size));
    background-position: var(--theme-bg-position-mobile, var(--theme-bg-position));
    background-repeat: var(--theme-bg-repeat-mobile, var(--theme-bg-repeat));

    opacity: var(--theme-bg-opacity-mobile, var(--theme-bg-opacity));
    filter: var(--theme-bg-filter-mobile, var(--theme-bg-filter));

    -webkit-mask-image: var(--theme-bg-mask-mobile, var(--theme-bg-mask));
    mask-image: var(--theme-bg-mask-mobile, var(--theme-bg-mask));
  }
}

/* ============================================================
   Theme Menu UI (popover)
   - Keep styling generic so it can be used on both pages.
============================================================ */

/* Button (small icon) */
#themeMenuBtn{
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(255,255,255,0.03);
  color: rgba(255,255,255,0.78);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
#themeMenuBtn:hover{
  transform: translateY(-0.5px);
  background: rgba(255,255,255,0.06);
  border-color: rgba(148, 163, 184, 0.34);
}
#themeMenuBtn:active{
  transform: translateY(0);
}

/* icon size */
#themeMenuBtn svg{
  width: 18px;
  height: 18px;
}

/* Light tone: button in dark text */
:root[data-theme="light"] #themeMenuBtn{
  border-color: rgba(10, 15, 25, 0.18);
  background: rgba(10,15,25,0.03);
  color: rgba(10,15,25,0.78);
}
:root[data-theme="light"] #themeMenuBtn:hover{
  background: rgba(10,15,25,0.06);
  border-color: rgba(10, 15, 25, 0.26);
}

/* Popover */
.theme-popover{
  position: fixed;
  top: 66px;
  right: 18px;
  width: min(320px, calc(100vw - 36px));
  z-index: 999;

  border-radius: 16px;
  padding: 12px;

  background: rgba(2, 6, 23, 0.58);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 18px 60px rgba(0,0,0,0.38);
  backdrop-filter: blur(16px);

  color: rgba(255,255,255,0.92);
}
:root[data-theme="light"] .theme-popover{
  background: rgba(255,255,255,0.78);
  border-color: rgba(10, 15, 25, 0.16);
  box-shadow: 0 18px 60px rgba(10,15,25,0.12);
  color: rgba(10,15,25,0.92);
}

.theme-popover .row{
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px 4px;
}

.theme-popover .label{
  font-size: 12px;
  letter-spacing: 0.06em;
  opacity: 0.78;
}

.theme-popover select{
  width: 100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.20);
  background: rgba(255,255,255,0.04);
  color: inherit;
  outline: none;
}
:root[data-theme="light"] .theme-popover select{
  border-color: rgba(10, 15, 25, 0.14);
  background: rgba(10,15,25,0.03);
}

.theme-popover .seg{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.theme-popover .seg button{
  border: 1px solid rgba(148, 163, 184, 0.20);
  background: rgba(255,255,255,0.04);
  color: inherit;
  border-radius: 12px;
  padding: 10px 10px;
  cursor: pointer;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.theme-popover .seg button[data-active="1"]{
  border-color: rgba(56, 189, 248, 0.55);
  box-shadow: 0 0 0 4px rgba(56,189,248,0.10);
}

:root[data-theme="light"] .theme-popover .seg button{
  border-color: rgba(10, 15, 25, 0.14);
  background: rgba(10,15,25,0.03);
}

.theme-popover .hint{
  margin-top: 8px;
  font-size: 11px;
  opacity: 0.70;
  line-height: 1.5;
}

/* ============================================================
   AI Call (visitor UI) – Light tone adjustments
   - Keep these scoped so it never affects the manage screen.
============================================================ */

/* Mark the call UI in JS: body[data-app="ai-call"] */

:root[data-theme="light"] body[data-app="ai-call"]{
  /* Background base */
  --bg-base: radial-gradient(circle at 50% -14%, #ffffff 0, #f4f6fb 46%, #eef1f8 100%);

  /* Subtle vignette (keep edges clean but not too dark) */
  --vignette:
    radial-gradient(ellipse at 50% 32%,
      rgba(255,255,255,0) 0%,
      rgba(255,255,255,0.0) 62%,
      rgba(15,20,35,0.06) 100%);

  /* Veil layers tuned for light background */
  --veil-layers:
    radial-gradient(circle at 18% -12%, rgba(10, 15, 25, 0.03), transparent 55%),
    radial-gradient(circle at 78% 125%, rgb(var(--gold-rgb) / 0.05), transparent 62%),
    radial-gradient(circle at 48% 145%, rgba(10, 15, 25, 0.05), transparent 70%);

  --veil-opacity-1: 0.22;
  --veil-opacity-2: 0.18;

  /* Text */
  --text: rgba(10, 15, 25, 0.94);
  --muted: rgba(10, 15, 25, 0.72);
  --muted2: rgba(10, 15, 25, 0.54);
  --logo-color: rgba(10, 15, 25, 0.72);

  /* Lines */
  --line-soft: rgba(10, 15, 25, 0.14);
  --line-mid: rgba(10, 15, 25, 0.16);

  /* Shadows */
  --shadow-soft: 0 22px 60px rgba(10, 15, 25, 0.12);
  --text-glow: 0 10px 34px rgba(10, 15, 25, 0.10);

  /* Bottom bar */
  --bar-strong: rgba(255, 255, 255, 0.72);
  --bar-soft: rgba(255, 255, 255, 0.30);

  /* Grain in light mode: reduce */
  --grain-opacity: 0.02;
}

/* Header / input bar hard-coded backgrounds: override in light */
:root[data-theme="light"] body[data-app="ai-call"] .app-header{
  background: linear-gradient(to bottom, rgba(255,255,255,0.76), transparent);
}

/* Mobile patch in index.html uses !important dark background. Override it. */
@media (max-width: 520px){
  :root[data-theme="light"] body[data-app="ai-call"] .app-header,
  :root[data-theme="light"] body[data-app="ai-call"] .input-bar{
    background: rgba(255,255,255,0.86) !important;
  }
}

/* In light mode, the gradient text becomes hard to read; switch to plain text */
:root[data-theme="light"] body[data-app="ai-call"] .msg-text{
  background-image: none !important;
  -webkit-text-fill-color: currentColor !important;
  color: var(--text) !important;
  -webkit-background-clip: border-box !important;
  background-clip: border-box !important;
  text-shadow: 0 12px 34px rgba(10, 15, 25, 0.10);
}

/* Buttons that were tuned for dark */
:root[data-theme="light"] body[data-app="ai-call"] #start span{
  color: rgba(10,15,25,0.80);
}
:root[data-theme="light"] body[data-app="ai-call"] #start:not(:disabled):hover span{
  color: rgba(10,15,25,0.92);
  text-shadow: 0 0 10px rgba(10,15,25,0.10);
}

/* Utility: AI Call header right cluster */
body[data-app="ai-call"] .app-header .header-right{
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

/* ============================
   Theme Popover (theme.js の tp-* に対応)
   ============================ */

.theme-popover .tp-title{
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.theme-popover .tp-row{
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
  align-items: center;
  margin: 10px 0;
}

.theme-popover .tp-label{
  font-size: 13px;
  opacity: .75;
}

.theme-popover select{
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.35);
  color: inherit;
  outline: none;
}

.theme-popover .tp-seg{
  display:flex;
  gap:10px;
}

.theme-popover .tp-seg button{
  flex: 1;
  height: 42px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(0,0,0,.25);
  color: inherit;
  cursor: pointer;
  font-weight: 600;
}

.theme-popover .tp-seg button[aria-pressed="true"]{
  border-color: rgba(80,180,255,.55);
  box-shadow: 0 0 0 2px rgba(80,180,255,.15);
}

.theme-popover .tp-foot{
  display:flex;
  justify-content:flex-end;
  margin-top: 14px;
}

.theme-popover .tp-close{
  height: 40px;
  padding: 0 18px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.18);
  color: inherit;
  cursor: pointer;
}
