:root {
  --portal-bg: #080604;
  --portal-panel: #100c08;
  --portal-ink: #f3dfb6;
  --portal-muted: #ab9470;
  --portal-gold: #cfab68;
  --portal-line: rgba(220, 186, 124, 0.2);
  --portal-danger: #c7796d;
}

#account-button,
#sound-button {
  position: fixed;
  top: max(0.6rem, env(safe-area-inset-top));
  width: 42px;
  height: 42px;
  border: 1px solid rgba(216, 187, 132, 0.16);
  border-radius: 50%;
  background: rgba(5, 4, 3, 0.46);
  color: var(--muted);
  z-index: 32;
  cursor: pointer;
  font: 400 0.85rem/1 'LXGW WenKai Lite', serif;
  opacity: 0.58;
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  -webkit-tap-highlight-color: transparent;
}

#account-button { right: max(0.7rem, env(safe-area-inset-right)); }
#sound-button { right: calc(max(0.7rem, env(safe-area-inset-right)) + 50px); }
#account-button:hover, #account-button:focus-visible,
#sound-button:hover, #sound-button:focus-visible { opacity: 1; border-color: rgba(216, 187, 132, 0.48); outline: none; }
#account-button[data-credit]::after {
  content: attr(data-credit);
  position: absolute;
  right: -4px;
  bottom: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #cfab68;
  color: #120d07;
  border: 2px solid #080604;
  font: 700 0.62rem/1 system-ui, sans-serif;
}

#portal-root { position: fixed; inset: 0; z-index: 120; pointer-events: none; }
#portal-root.portal-open { pointer-events: auto; }
.portal-veil {
  position: absolute;
  inset: 0;
  border: 0;
  opacity: 0;
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 240ms ease;
}
.portal-open .portal-veil { opacity: 1; }
.portal-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: min(520px, 94vw);
  height: 100%;
  padding: max(1.1rem, env(safe-area-inset-top)) max(1.1rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) 1.4rem;
  overflow: hidden;
  transform: translateX(104%);
  transition: transform 320ms cubic-bezier(.22,.76,.25,1);
  background:
    radial-gradient(circle at 85% 3%, rgba(174, 127, 56, 0.13), transparent 32%),
    linear-gradient(105deg, #070504, #100b07 52%, #080604);
  border-left: 1px solid var(--portal-line);
  box-shadow: -28px 0 90px rgba(0, 0, 0, 0.72);
  color: var(--portal-ink);
  font-family: 'LXGW WenKai Lite', 'Kaiti SC', serif;
  touch-action: pan-y;
  user-select: text;
  -webkit-user-select: text;
}
.portal-drawer::before {
  content: '';
  position: absolute;
  inset: 10px;
  pointer-events: none;
  border: 1px solid rgba(207, 171, 104, 0.1);
}
.portal-open .portal-drawer { transform: translateX(0); }
.portal-frame { position: relative; z-index: 1; height: 100%; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.portal-head { display: flex; align-items: center; justify-content: space-between; padding: 0.35rem 0.15rem 1rem; }
.portal-kicker { color: var(--portal-gold); font-size: 0.72rem; letter-spacing: 0.24em; }
.portal-head h2 { margin-top: 0.15rem; font: italic 1.25rem/1.3 Georgia, serif; letter-spacing: 0.02em; }
.portal-close { width: 40px; height: 40px; border: 0; background: transparent; color: var(--portal-muted); font-size: 1.5rem; cursor: pointer; }
.portal-nav { display: flex; gap: 0.35rem; padding: 0 0 0.9rem; overflow-x: auto; scrollbar-width: none; }
.portal-nav::-webkit-scrollbar { display: none; }
.portal-nav button {
  flex: 0 0 auto;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 0.5rem 0.4rem;
  background: transparent;
  color: var(--portal-muted);
  font: inherit;
  cursor: pointer;
}
.portal-nav button[aria-selected="true"] { color: var(--portal-ink); border-color: var(--portal-gold); }
.portal-body { overflow-y: auto; overscroll-behavior: contain; padding: 0.35rem 0.15rem 2rem; }
.portal-section { animation: portalReveal 220ms ease both; }
@keyframes portalReveal { from { opacity: 0; transform: translateY(6px); } }
.portal-lead { color: var(--portal-muted); line-height: 1.75; font-size: 0.9rem; margin-bottom: 1rem; }
.portal-card {
  border: 1px solid var(--portal-line);
  border-radius: 15px;
  background: rgba(0, 0, 0, 0.2);
  padding: 1rem;
  margin-bottom: 0.8rem;
}
.portal-balance { display: flex; align-items: end; gap: 0.55rem; }
.portal-balance strong { color: var(--portal-ink); font: 400 clamp(2.4rem, 10vw, 4rem)/0.9 Georgia, serif; }
.portal-balance span { color: var(--portal-muted); }
.portal-label { color: var(--portal-gold); font-size: 0.73rem; letter-spacing: 0.12em; margin-bottom: 0.55rem; }
.portal-form { display: grid; gap: 0.7rem; }
.portal-field { display: grid; gap: 0.3rem; color: var(--portal-muted); font-size: 0.76rem; }
.portal-field input {
  min-height: 46px;
  width: 100%;
  border: 1px solid var(--portal-line);
  border-radius: 10px;
  background: #050403;
  color: var(--portal-ink);
  padding: 0.7rem 0.8rem;
  font: 400 1rem/1.2 'LXGW WenKai Lite', serif;
  user-select: text;
  -webkit-user-select: text;
}
.portal-field input:focus { outline: 1px solid var(--portal-gold); border-color: var(--portal-gold); }
.portal-actions { display: flex; flex-wrap: wrap; gap: 0.55rem; margin-top: 0.2rem; }
.portal-button {
  min-height: 43px;
  border: 1px solid var(--portal-line);
  border-radius: 10px;
  padding: 0.62rem 0.9rem;
  background: transparent;
  color: var(--portal-ink);
  font: inherit;
  cursor: pointer;
}
.portal-button:hover, .portal-button:focus-visible { border-color: var(--portal-gold); outline: none; }
.portal-button.primary { background: var(--portal-ink); border-color: var(--portal-ink); color: #120d07; }
.portal-button.danger { color: var(--portal-danger); }
.portal-button:disabled { opacity: 0.38; cursor: not-allowed; }
.portal-link { border: 0; padding: 0; background: none; color: var(--portal-gold); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.portal-auth-switch { display: flex; flex-wrap: wrap; gap: 0.85rem; margin: 0.2rem 0 1rem; }
.portal-auth-switch button { border: 0; border-bottom: 1px solid transparent; padding: 0.25rem 0; background: none; color: var(--portal-muted); font: inherit; cursor: pointer; }
.portal-auth-switch button.active { color: var(--portal-ink); border-color: var(--portal-gold); }
.portal-auth-prologue { margin: 0 0 1.7rem; }
.portal-ink-prompt {
  min-height: 1.4em;
  margin: 0 0 0.75rem;
  color: var(--portal-ink);
  font: 400 clamp(1.65rem, 5vw, 2.65rem)/1.35 'LXGW WenKai Lite', serif;
  letter-spacing: 0.06em;
}
.portal-ink-copy {
  min-height: 2em;
  color: var(--portal-muted);
  font: 400 clamp(0.95rem, 2.4vw, 1.18rem)/1.9 'LXGW WenKai Lite', serif;
  letter-spacing: 0.04em;
}
.portal-ink-unit {
  display: inline-block;
  opacity: 0;
  filter: blur(4px);
  animation: portalInkAppear 1.05s ease forwards;
}
@keyframes portalInkAppear { to { opacity: 0.94; filter: blur(0); } }
.portal-auth-ui, .portal-auth-prologue + .portal-auth-switch {
  opacity: 0;
  filter: blur(4px);
  animation: portalInkPanel 1.2s 1.65s ease forwards;
}
@keyframes portalInkPanel { to { opacity: 1; filter: blur(0); } }
.portal-turnstile { min-height: 68px; overflow: hidden; }
.portal-message { min-height: 1.4rem; margin-top: 0.6rem; color: var(--portal-muted); font-size: 0.78rem; line-height: 1.5; }
.portal-message.error { color: var(--portal-danger); }
.portal-packages { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
.portal-package { position: relative; display: grid; gap: 0.2rem; text-align: left; }
.portal-package strong { font: 400 1.4rem/1.2 Georgia, serif; }
.portal-package small { color: var(--portal-muted); }
.portal-package::after { content: '¥1 / 次'; position: absolute; right: 0.7rem; top: 0.65rem; color: var(--portal-gold); font-size: 0.65rem; }
.portal-list { display: grid; gap: 0.7rem; }
.portal-entry { border-bottom: 1px solid var(--portal-line); padding: 0 0 0.8rem; }
.portal-entry:last-child { border-bottom: 0; }
.portal-entry time { color: var(--portal-muted); font-size: 0.68rem; }
.portal-question { margin: 0.35rem 0; color: var(--portal-gold); font-size: 0.87rem; }
.portal-answer { white-space: pre-wrap; line-height: 1.75; font-size: 0.86rem; }
.portal-oracle { color: var(--portal-muted); font-size: 0.72rem; margin-bottom: 0.35rem; }
.portal-entry-tools { display: flex; justify-content: flex-end; margin-top: 0.4rem; }
.portal-entry-tools button { border: 0; background: none; color: var(--portal-muted); font: inherit; font-size: 0.72rem; cursor: pointer; }
.portal-empty { padding: 2.2rem 1rem; text-align: center; color: var(--portal-muted); line-height: 1.7; }
.portal-payment { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; }
.portal-payment small { color: var(--portal-muted); }
.portal-status { color: var(--portal-gold); }
.portal-toast {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  max-width: min(90vw, 520px);
  padding: 0.7rem 1rem;
  border: 1px solid var(--portal-line);
  border-radius: 999px;
  background: rgba(8, 6, 4, 0.92);
  color: var(--portal-ink);
  font: 0.8rem/1.45 'LXGW WenKai Lite', serif;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
  box-shadow: 0 10px 45px rgba(0, 0, 0, 0.5);
  z-index: 180;
}
.portal-toast.visible { opacity: 1; transform: translate(-50%, 0); }
.portal-sound-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.8rem; }
.portal-sound-row input[type="range"] { width: 100%; accent-color: var(--portal-gold); }
.portal-track { font: italic 1.45rem/1.3 Georgia, serif; color: var(--portal-ink); }
.portal-attribution { color: var(--portal-muted); font-size: 0.75rem; line-height: 1.65; }
.portal-legal { display: flex; flex-wrap: wrap; gap: 0.45rem 1rem; }
.portal-legal a { color: var(--portal-gold); text-decoration: none; border-bottom: 1px solid rgba(207, 171, 104, 0.28); }
.portal-legal a:hover { border-color: var(--portal-gold); }

/* Anonymous authentication is part of the page, not a dashboard dialog. */
#portal-root.portal-auth-scene .portal-veil { background: rgba(0, 0, 0, 0.82); }
#portal-root.portal-auth-scene .portal-drawer {
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  transform: none;
  opacity: 0;
  visibility: hidden;
  border: 0;
  border-radius: 0;
  background:
    radial-gradient(ellipse at 50% 43%, rgba(132, 91, 36, 0.08), transparent 55%),
    rgba(0, 0, 0, 0.74);
  box-shadow: none;
  transition: opacity 280ms ease, visibility 0s linear 280ms;
}
#portal-root.portal-auth-scene.portal-open .portal-drawer {
  opacity: 1;
  visibility: visible;
  transition: opacity 280ms ease;
}
#portal-root.portal-auth-scene .portal-drawer::before { display: none; }
#portal-root.portal-auth-scene .portal-frame { grid-template-rows: auto auto minmax(0, 1fr); }
#portal-root.portal-auth-scene .portal-head { justify-content: flex-end; }
#portal-root.portal-auth-scene .portal-head > div { display: none; }
#portal-root.portal-auth-scene .portal-nav { justify-content: center; padding-bottom: 0; }
#portal-root.portal-auth-scene .portal-body {
  display: grid;
  place-items: center;
  width: 100%;
  padding: 1rem 0 3rem;
}
#portal-root.portal-auth-scene .portal-section { width: min(620px, 90vw); }
#portal-root.portal-auth-scene .portal-field { font-size: 0.82rem; letter-spacing: 0.06em; }
#portal-root.portal-auth-scene .portal-field input {
  border: 0;
  border-bottom: 1px solid rgba(220, 186, 124, 0.32);
  border-radius: 0;
  background: transparent;
  padding-inline: 0.2rem;
  font-size: 1.05rem;
}
#portal-root.portal-auth-scene .portal-button { border-radius: 999px; }
#portal-root.portal-auth-scene .portal-button.primary {
  background: rgba(243, 223, 182, 0.92);
  box-shadow: 0 0 28px rgba(243, 223, 182, 0.08);
}

@media (max-width: 640px) {
  .portal-drawer {
    top: auto;
    bottom: 0;
    width: 100%;
    height: min(90dvh, 760px);
    padding: 0.9rem 1rem max(1rem, env(safe-area-inset-bottom));
    border-left: 0;
    border-top: 1px solid var(--portal-line);
    border-radius: 22px 22px 0 0;
    transform: translateY(104%);
  }
  .portal-open .portal-drawer { transform: translateY(0); }
  .portal-drawer::after { content: ''; position: absolute; top: 7px; left: 50%; width: 36px; height: 3px; border-radius: 3px; background: var(--portal-line); transform: translateX(-50%); }
  .portal-packages { grid-template-columns: 1fr 1fr; }
  #portal-root.portal-auth-scene .portal-drawer { inset: 0; height: 100%; border-radius: 0; }
  #portal-root.portal-auth-scene .portal-drawer::after { display: none; }
  #portal-root.portal-auth-scene .portal-body { align-items: start; padding-top: 4vh; }
}

@media (prefers-reduced-motion: reduce) {
  .portal-drawer, .portal-veil, .portal-section, .portal-toast { transition: none; animation: none; }
  .portal-ink-unit, .portal-auth-ui, .portal-auth-prologue + .portal-auth-switch {
    animation: none;
    opacity: 1;
    filter: none;
  }
}
