/* ==========================================================================
 * ok_study_v103_flagship_omni.css — study.ok.st Production Flagship (v103.0)
 * Sunlit Washi (#FAF9F5) Bold Ma (75%-85% Hero / 65%+ Workspace) & Modern Web
 * ========================================================================== */

:root {
  --v103-bg-washi: #faf9f5;
  --v103-surface: #ffffff;
  --v103-surface-soft: #f5f2eb;
  --v103-ink: #0f172a;
  --v103-muted: #475569;
  --v103-accent: #0f766e;
  --v103-accent-deep: #115e59;
  --v103-accent-soft: #f0fdfa;
  --v103-gold: #b45309;
  --v103-gold-soft: #fef3c7;
  --v103-hairline: #e6e1d6;
  --v103-radius: 16px;
}

html:not(.dark) body,
html:not(.dark) #ok-main-workspace {
  background-color: var(--v103-bg-washi);
  color: var(--v103-ink);
}

/* --- 1. Scroll-State Header Auto-Tuck (< 12% viewport height) --- */
@supports (container-type: scroll-state) {
  html {
    container-type: scroll-state;
  }
}

#ok-global-header {
  max-block-size: 11.5dvh;
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.2s ease;
}

#ok-global-header:focus-within {
  transform: none;
}

@supports (container-type: scroll-state) {
  @container scroll-state((scrolled: bottom) and (scrollable: top)) {
    #ok-global-header:not(:focus-within) {
      transform: translateY(-100%);
    }
  }
}

html.v103-header-tucked #ok-global-header:not(:focus-within) {
  transform: translateY(-100%);
}

/* --- 2. Minimum 48px Touch Targets & Left/Right Thumb Parity --- */
.v103-tap-target,
.v103-tab-btn,
.v103-stage-chip,
.v103-action-btn {
  min-block-size: 48px;
  min-inline-size: 48px;
}

#ok-global-header nav button {
  min-block-size: 42px;
  white-space: nowrap;
  flex-shrink: 0;
}

.v103-sm-only {
  display: inline;
}

@media (min-width: 640px) {
  .v103-sm-only {
    display: none !important;
  }
}

@media (min-width: 1280px) {
  #ok-global-header > div {
    max-width: 90rem !important;
  }
  .v103-brand-wrap {
    flex: 0 0 auto !important;
  }
  #brand-main-title {
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }
  #ok-global-header nav {
    flex: 1 1 auto;
    justify-content: center;
    gap: 0.125rem;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #ok-global-header nav button {
    padding-inline: 0.45rem;
    font-size: 12px;
  }
}

.v103-thumb-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-start;
  transition: justify-content 0.2s ease;
}

html[data-handedness="right"] .v103-thumb-rail {
  justify-content: flex-end;
}

.v103-mobile-dock {
  position: fixed;
  inset-block-end: max(0.75rem, env(safe-area-inset-bottom));
  inset-inline-start: 0.75rem;
  inset-inline-end: auto;
  z-index: 45;
  display: flex;
  gap: 0.5rem;
  padding: 0.375rem;
  max-block-size: 10dvh;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--v103-hairline);
  border-radius: 9999px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(8px);
}

html[data-handedness="right"] .v103-mobile-dock {
  inset-inline-start: auto;
  inset-inline-end: 5.25rem;
}

@media (min-width: 1024px) {
  .v103-mobile-dock {
    display: none !important;
  }
}

/* --- 3. Faster SPA Views (content-visibility: hidden + inert + 0px collapse) --- */
.v103-view-hidden {
  content-visibility: hidden;
  display: block;
  block-size: 0 !important;
  min-block-size: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
}

@supports not (content-visibility: hidden) {
  .v103-view-hidden {
    display: none;
  }
}

/* --- 4. Directional View Transitions --- */
@keyframes v103-slide-in-right {
  from {
    opacity: 0;
    transform: translateX(22px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes v103-slide-out-left {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(-22px);
  }
}

@keyframes v103-slide-in-left {
  from {
    opacity: 0;
    transform: translateX(-22px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes v103-slide-out-right {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(22px);
  }
}

:active-view-transition-type(v103-forward)::view-transition-old(root) {
  animation: 220ms cubic-bezier(0.22, 1, 0.36, 1) both v103-slide-out-left;
}

:active-view-transition-type(v103-forward)::view-transition-new(root) {
  animation: 260ms cubic-bezier(0.22, 1, 0.36, 1) both v103-slide-in-right;
}

:active-view-transition-type(v103-back)::view-transition-old(root) {
  animation: 220ms cubic-bezier(0.22, 1, 0.36, 1) both v103-slide-out-right;
}

:active-view-transition-type(v103-back)::view-transition-new(root) {
  animation: 260ms cubic-bezier(0.22, 1, 0.36, 1) both v103-slide-in-left;
}

/* --- 5. Scoped Transitions (Live Stage Reorder & Match-Element) --- */
#v103-scoped-arena-stage {
  container-type: inline-size;
}

.v103-stage-node {
  view-transition-name: match-element;
  transition: transform 0.2s ease, border-color 0.25s ease;
}

/* --- 6. Bold Ma Layout Surfaces & Typographic Hierarchy --- */
.v103-canvas-wrap {
  max-inline-size: 72rem;
  inline-size: 100%;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 3rem;
}

.v103-canvas-wrap > *,
#v103-scoped-arena-stage > * {
  min-inline-size: 0;
  max-inline-size: 100%;
}

.v103-card {
  background: var(--v103-surface);
  border: 1px solid var(--v103-hairline);
  border-radius: var(--v103-radius);
  padding: clamp(1.25rem, 3vw, 2.5rem);
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow-x: clip;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.03);
}

.v103-prose-measure {
  max-inline-size: 62ch;
  line-height: 1.9;
}

/* --- 7. Anchor Positioning Tab Underline (border-block-end only, Forced Colors safe) --- */
.v103-tab-list {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
  margin: 0;
  padding: 0 0 0.25rem 0;
  border-block-end: 1px solid var(--v103-hairline);
}

.v103-tab-btn[aria-selected="true"] {
  anchor-name: --v103-active-tab;
  color: var(--v103-accent-deep);
  font-weight: 700;
}

@supports (position-anchor: auto) {
  .v103-tab-list::before {
    content: "";
    position: absolute;
    position-anchor: --v103-active-tab;
    inset-block-end: -1px;
    inset-inline-start: anchor(left);
    inline-size: anchor-size(width);
    block-size: 0;
    border-block-end: 3px solid var(--v103-accent);
    transition: inset-inline-start 0.22s cubic-bezier(0.22, 1, 0.36, 1),
      inline-size 0.22s cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
  }
}

@supports not (position-anchor: auto) {
  .v103-tab-btn[aria-selected="true"] {
    border-block-end: 3px solid var(--v103-accent);
  }
}

/* --- 8. LW-11 Tokiwa Card Patina Maturation Tiers --- */
.v103-patina-card {
  border-width: 2px;
  border-style: solid;
  border-radius: 18px;
  background: var(--v103-surface);
  transition: border-color 0.35s ease, box-shadow 0.35s ease;
}

.v103-patina-card[data-patina="kina"] {
  border-color: #d6d1c4;
}

.v103-patina-card[data-patina="asagi"] {
  border-color: #6ee7b7;
  box-shadow: 0 4px 16px rgba(15, 118, 110, 0.08);
}

.v103-patina-card[data-patina="tokiwa"] {
  border-color: #0d9488;
  box-shadow: 0 8px 24px rgba(13, 148, 136, 0.14);
}

.v103-patina-card[data-patina="gold"] {
  border-color: #b45309;
  box-shadow: 0 10px 28px rgba(180, 83, 9, 0.16);
}

/* --- 9. Scrollytelling Sync Progress (full @supports gate + IO fallback) --- */
.v103-scroll-rail {
  timeline-scope: --v103-stage-scroll;
}

.v103-scroll-meter {
  block-size: 4px;
  inline-size: 100%;
  background: var(--v103-surface-soft);
  border-radius: 9999px;
  overflow: hidden;
}

.v103-scroll-meter-fill {
  block-size: 100%;
  inline-size: 100%;
  transform-origin: left center;
  transform: scaleX(var(--v103-io-progress, 0.25));
  background: var(--v103-accent);
  transition: transform 0.2s ease-out;
}

@supports ((animation-timeline: scroll()) and (animation-range: 0% 100%)) {
  .v103-scroll-meter-fill {
    animation: v103-grow-x linear both;
    animation-timeline: scroll(nearest block);
    animation-range: entry 0% exit 100%;
  }

  @keyframes v103-grow-x {
    from {
      transform: scaleX(0.15);
    }
    to {
      transform: scaleX(1);
    }
  }
}

.v103-story-beat {
  opacity: 0.72;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.v103-story-beat.is-in-view {
  opacity: 1;
  transform: translateY(0);
}

/* --- 10. Interest-Triggered Tooltips ([interestfor] + popover="hint") --- */
.v103-hint-popover {
  margin: 0;
  max-inline-size: min(22rem, 88vw);
  padding: 0.875rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--v103-hairline);
  background: var(--v103-surface);
  color: var(--v103-ink);
  font-size: 0.875rem;
  line-height: 1.65;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

@supports (position-area: block-start) {
  .v103-hint-popover {
    position-area: block-start span-inline-end;
    position-try-fallbacks: flip-block, flip-inline;
    margin-block-end: 0.5rem;
  }
}

/* --- 11. Exclusive Accordion + until-found Inner Wrapper Padding --- */
details.v103-accordion {
  border: 1px solid var(--v103-hairline);
  border-radius: 14px;
  background: var(--v103-surface);
  min-inline-size: 0;
  max-inline-size: 100%;
}

details.v103-accordion summary {
  min-block-size: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

details.v103-accordion summary::-webkit-details-marker {
  display: none;
}

[hidden="until-found"] {
  content-visibility: hidden;
  padding: 0;
}

.v103-until-found-inner {
  padding: 1rem 1.25rem 1.5rem;
  border-block-start: 1px solid var(--v103-hairline);
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

/* --- 12. Track B Vertical Tategumi Literary Reader (Shiroku 50%+ Ma) --- */
/* Note: vertical-rl rotates logical inline/block axes, so physical width/height are required here. */
.v103-tategumi-frame {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  height: clamp(22rem, 48vh, 30rem);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
  padding: clamp(1.25rem, 3vw, 2.25rem);
  background: #fdfcf7;
  border: 1px solid var(--v103-hairline);
  border-radius: 14px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-size: 1.05rem;
  line-height: 2.2;
  letter-spacing: 0.04em;
  color: #1c1917;
}

/* --- 13. Zoom Dialog (closedby="any" + opt-in data-zoomable) --- */
dialog.v103-zoom-dialog {
  max-inline-size: min(94vw, 68rem);
  max-block-size: 90dvh;
  padding: 1.5rem;
  border: 1px solid var(--v103-hairline);
  border-radius: 20px;
  background: var(--v103-surface);
  color: var(--v103-ink);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
}

dialog.v103-zoom-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
}

/* --- 14. Reduced Motion Respect --- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
