/* Тихий курс — MIT License */

:root {
  --bg: #0a0d14;
  --surface: rgba(17, 21, 32, 0.55);
  --surface-strong: rgba(17, 21, 32, 0.82);
  --text: #e9edf5;
  --text-dim: #9aa6ba;
  --accent: #7fd4c2;
  --accent-soft: rgba(127, 212, 194, 0.14);
  --border: rgba(255, 255, 255, 0.12);
  --blur: 18px;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Сцена ---------- */

#scene-root {
  position: fixed;
  inset: 0;
  z-index: 0;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
}

#scene-video {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: none;
  overflow: hidden;
}

#scene-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Необязательная сцена «Океан (WebGPU)» */
.scene-frame {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: none;
  z-index: 0;
  background: #000;
}

/* ---------- Карточка курсов ---------- */

.ambient-content {
  --content-bottom: max(16px, env(safe-area-inset-bottom));
  position: fixed;
  inset-inline: 0;
  bottom: calc(var(--content-bottom) + var(--media-credit-space, 0px));
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr) minmax(0, 340px);
  align-items: end;
  gap: 16px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  max-height: calc(100vh - 184px - var(--content-bottom) - var(--media-credit-space, 0px));
  max-height: calc(100dvh - max(184px, calc(env(safe-area-inset-top) + 174px)) - var(--content-bottom) - var(--media-credit-space, 0px));
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  pointer-events: none;
}

.ambient-content > * { min-width: 0; }

#quotes-card {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  padding: 14px 16px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  z-index: 10;
  pointer-events: auto;
}

.quotes-status {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text-dim);
}

.quotes-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quote-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  overflow-wrap: anywhere;
}

.quote-code {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  min-width: 46px;
}

.quote-value {
  font-size: 21px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.quote-change {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.quotes-source {
  margin: 10px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

.quotes-source a {
  color: var(--accent);
}

.quotes-source a:focus-visible {
  outline-color: var(--accent);
}

.quotes-stale {
  margin: 8px 0 0;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(232, 162, 162, 0.12);
  color: #e8a2a2;
  font-size: 11px;
}

body.tc-hide-numbers #quotes-card {
  display: none;
}

/* ---------- Фраза заставки ---------- */

.ambient-phrase {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  width: min(560px, 100%);
  margin: 0;
  text-align: center;
  padding: 0.65em 1em;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(9, 16, 27, 0.78);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  font-size: clamp(1.125rem, calc(1rem + 0.5vw), 1.375rem);
  font-weight: 500;
  line-height: 1.55;
  color: #f3f6fc;
  z-index: 5;
  pointer-events: auto;
  overflow-wrap: anywhere;
}

.ambient-phrase:empty { display: none; }
body.tc-hide-numbers .ambient-phrase { grid-column: 1 / -1; }

@media (max-width: 1100px) {
  .ambient-content { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .ambient-phrase {
    grid-column: 1;
    grid-row: 1;
  }
  #quotes-card { grid-row: 2; justify-self: center; max-width: 340px; }
}

/* Independent Forex source; shares the existing scroll area with CBR and phrases. */
#forex-card { grid-column: 3; grid-row: 1; width: 100%; max-width: 340px; min-width: 0; padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); background: #101923; color: #edf2f7; pointer-events: auto; overflow-wrap: anywhere; }
#forex-heading { font-size: 18px; margin: 0 0 8px; }
#forex-card p { font-size: 14px; line-height: 1.5; margin: 8px 0; }
#forex-card .forex-source { color: #c0ccda; }
#forex-card .forex-warning { color: #ffe49e; }
#forex-card a { color: #b6dcff; text-decoration: underline; }
#forex-card a:focus-visible { outline: 2px solid #ffe49e; outline-offset: 3px; }
#forex-card .forex-row { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid #475767; }
#forex-card .forex-code { font-size: 0.875rem; color: #c0ccda; }
#forex-card .forex-value { font-size: 1rem; font-variant-numeric: tabular-nums; text-align: right; }
#forex-card .forex-stale { background: #332f20; color: #ffe49e; font-size: 0.8125rem; padding: 0.375rem 0.5rem; border-radius: 4px; }
#forex-card .forex-methodology { font-size: 0.75rem; color: #c0ccda; opacity: 0.8; margin-top: 0.5rem; }
#forex-card .forex-source { font-size: 0.75rem; color: #c0ccda; }
body.tc-hide-numbers #forex-card { display: none; }
@media (max-width: 1100px) { .ambient-content #forex-card { grid-column: 1; grid-row: 4; justify-self: center; } }

/* ---------- Верхние круглые кнопки ---------- */

.top-actions {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 20;
}

.round-button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.round-button:hover {
  background: var(--surface-strong);
  border-color: rgba(255, 255, 255, 0.22);
}

.round-button--active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.round-button__icon {
  display: block;
}

/* ---------- Панель настроек ---------- */

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(340px, 92vw);
  transform: translateX(105%);
  transition: transform 0.32s ease;
  background: var(--surface-strong);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-left: 1px solid var(--border);
  z-index: 50;
  overflow-y: auto;
  padding: 20px;
}

body.settings-open .settings-panel {
  transform: translateX(0);
}

.settings-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.settings-panel__head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.settings-group {
  margin-bottom: 22px;
}

.settings-group h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.options-list,
.options-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.option-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.option-button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.settings-label {
  display: block;
  margin: 0 0 8px;
  font-size: 14px;
}

.volume {
  width: 100%;
  accent-color: var(--accent);
}

#sound-status,
#sound-credit {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}

#sound-credit {
  display: inline-block;
  margin-bottom: 8px;
}

#sound-credit[hidden] { display: none; }

.settings-select,
.settings-panel select {
  color-scheme: dark;
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

/* Native popup options can otherwise inherit light text over the OS light menu. */
.settings-panel select option {
  color: var(--text);
  background: #1c2330;
}

.settings-action {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(127, 212, 194, 0.4);
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
}

/* ---------- Атрибуция медиа ---------- */

.media-attribution {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: fit-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 4px 10px;
  border-radius: 8px;
  background: #101923;
  color: #c0ccda;
  font-size: 12px;
  line-height: 1.5;
  z-index: 11;
  text-align: right;
  pointer-events: auto;
  overflow-wrap: anywhere;
}

.media-attribution a {
  color: var(--accent);
}

.media-attribution a:focus-visible {
  outline-color: var(--accent);
}

/* ---------- Ненавязчивое сообщение ---------- */

.scene-toast {
  position: fixed;
  left: 50%;
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 88px));
  transform: translate(-50%, 8px);
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.scene-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Страница «О проекте» ---------- */

.about {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background: rgba(10, 13, 20, 0.94);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
}

.about-inner {
  max-width: 680px;
  margin: 0 auto;
}

.about h1 {
  margin: 0 0 24px;
  font-size: 30px;
  font-weight: 600;
}

.about h2 {
  margin: 28px 0 8px;
  font-size: 19px;
  font-weight: 600;
}

.about p {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
}

.about code {
  font-size: 13px;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
}

.about a {
  color: var(--accent);
}

.about-back {
  margin-top: 32px;
  font-size: 15px;
}

/* Compact rates: essential metadata stays visible, explanatory details can expand. */
#quotes-card { background: #101923; color: #edf2f7; }
.quotes-title { font-size: 1rem; margin: 0 0 0.25rem; }
.quotes-unit, .quotes-baseline, .quotes-source { font-size: 0.875rem; color: #c0ccda; }
.quotes-unit { margin: 0 0 0.5rem; }
.quote-row { display: grid; grid-template-columns: 3rem minmax(0,1fr); gap: 0.2rem 0.5rem; padding: 0.5rem 0; border-bottom: 1px solid #475767; }
.quote-code { font-size: 1rem; min-width: 0; color: #c0ccda; }
.quote-value { text-align: right; }
.quote-change { grid-column: 1 / -1; text-align: right; font-size: 0.875rem; color: #c0ccda; }
.quotes-details summary { min-height: 44px; padding: 0.5rem 0; cursor: pointer; font-size: 0.875rem; }
.quotes-details summary:focus-visible { outline: 3px solid #ffe1a0; outline-offset: 3px; }
.quotes-stale { background: #332f20; color: #ffe49e; }
.quotes-baseline { margin: 0.5rem 0 0; }

/* ---------- Утилиты ---------- */

@media (max-height: 500px) {
  .top-actions { flex-direction: row; }
  .ambient-content {
    max-height: calc(100vh - 80px - var(--content-bottom) - var(--media-credit-space, 0px));
    max-height: calc(100dvh - max(80px, calc(env(safe-area-inset-top) + 72px)) - var(--content-bottom) - var(--media-credit-space, 0px));
  }
}

@media (max-height: 500px) and (min-width: 520px) and (max-width: 1100px) {
  .ambient-content { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ambient-content #quotes-card { grid-column: 1; grid-row: 1; }
  .ambient-content .ambient-phrase { grid-column: 2; grid-row: 1; }
  body.tc-hide-numbers .ambient-content .ambient-phrase { grid-column: 1 / -1; }
}

@media (max-width: 360px) {
  #quotes-card {
    padding: 12px;
  }

  .quote-value {
    font-size: 19px;
  }

  .top-actions {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
  }
}

@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;
  }
}

/* The phrase remains one scrollable grid item alongside the rates. */
#phrase-text { margin: 0; white-space: pre-line; }
#phrase-credit { font-size: 0.85em; margin: 0.6em 0 0; }
#phrase-credit a { color: inherit; text-decoration: underline; }
.ambient-phrase { cursor: pointer; }
.phrase-advance { display: block; width: 100%; margin: 0; padding: 0; border: 0; border-radius: 4px; background: transparent; color: inherit; font: inherit; text-align: inherit; line-height: inherit; cursor: pointer; min-height: 44px; }
.phrase-advance:focus-visible, #phrase-credit a:focus-visible { outline: 3px solid #ffe1a0; outline-offset: 5px; }
.ambient-phrase[hidden] { display: none; }

/* Centered rates, selected in issue #56: one independent source at a time. */
.ambient-content {
  inset: max(84px, env(safe-area-inset-top)) 0 calc(var(--content-bottom) + var(--media-credit-space, 0px));
  max-height: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-block: 16px;
}
.ambient-content::before, .ambient-content::after { content: ''; flex: 1 0 0; }
.rate-source-picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; pointer-events: auto; flex-shrink: 0; }
.rate-source-picker button { min-height: 44px; padding: 8px 16px; background: #101923; border: 1px solid #65778a; border-radius: 24px; cursor: pointer; }
.rate-source-picker button[aria-pressed="true"] { color: #07120e; background: #bbd6a2; border-color: #bbd6a2; }
.ambient-content #quotes-card, .ambient-content #forex-card {
  width: 100%; max-width: 1280px; padding: 20px; flex: 0 0 auto;
  text-align: center; background: rgba(9,16,25,.88); border: 1px solid #506071;
  box-shadow: 0 8px 40px #0006; border-radius: 20px; overflow-wrap: anywhere;
}
.ambient-content #quotes-card[hidden], .ambient-content #forex-card[hidden] { display: none; }
.quotes-list, #forex-card .forex-list { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 20px; margin: 20px 0; }
.quote-row, #forex-card .forex-row { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px; border: 0; padding: 0; min-width: 0; }
.quote-code, #forex-card .forex-code { font-size: 1rem; order: 1; color: #d4dfeb; }
.quote-value, #forex-card .forex-value { font-size: clamp(2rem,5.5vw,5.5rem); font-weight: 600; line-height: 1.1; letter-spacing: -.04em; color: #bbd6a2; white-space: nowrap; order: 0; font-variant-numeric: tabular-nums; text-align: center; }
.quote-change { order: 2; font-size: .875rem; text-align: center; color: #d4dfeb; }
.quotes-title, #forex-heading { font-size: 1rem; font-weight: 500; margin: 0 0 8px; }
.quotes-unit, #forex-card > .forex-source:first-of-type { font-size: .875rem; color: #d4dfeb; }
.quotes-source, #forex-card .forex-source, #forex-card .forex-methodology { font-size: .875rem; color: #d4dfeb; opacity: 1; }
.quotes-details { max-width: 720px; margin-inline: auto; text-align: center; }
.quotes-details summary { width: fit-content; margin-inline: auto; }
.quotes-status:empty, .forex-status:empty { display: none; }
.ambient-content .ambient-phrase { flex: 0 0 auto; max-width: 640px; }
.ambient-content .media-attribution { flex: 0 0 auto; }

@media (max-width: 600px) {
  .ambient-content { gap: 12px; }
  .ambient-content #quotes-card, .ambient-content #forex-card { padding: 16px 12px; }
  .quotes-list, #forex-card .forex-list { grid-template-columns: minmax(0,1fr); gap: 20px; margin: 18px 0; }
  .quote-value, #forex-card .forex-value { font-size: clamp(2rem,13vw,4rem); }
}
@media (max-height: 500px) { .ambient-content { top: max(76px,env(safe-area-inset-top)); } }
/* Reserve one line when the extra return link is hidden, so visibility is stable. */
.about-back--top { min-block-size: 1.65em; }

.top-actions { flex-direction: row; }

/* Keep the selected source above the optional phrase on every viewport. */
.ambient-content::before { order: -1; }
.rate-source-picker { order: 0; }
.ambient-content #quotes-card, .ambient-content #forex-card { order: 1; }
.ambient-content .ambient-phrase { order: 2; }
.ambient-content::after { order: 3; }
.quotes-list, #forex-card .forex-list { grid-template-columns: minmax(0,1fr); }
.quote-value, #forex-card .forex-value { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
@media (min-width: 900px) {
  .quotes-list, #forex-card .forex-list { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .quote-value, #forex-card .forex-value { font-size: clamp(1.65rem,5vw,5.5rem); }
}
/* The chosen reference leaves the scene visible behind large, legible values. */
.ambient-content #quotes-card, .ambient-content #forex-card { background: transparent; border: 0; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
.quote-value, #forex-card .forex-value { text-shadow: 0 2px 14px #000,0 1px 3px #000; }
.quotes-title, #forex-heading, .quotes-unit, .quote-code, .quote-change, #forex-card .forex-code { text-shadow: 0 1px 5px #000,0 1px 12px #000; }
.quotes-source, #forex-card .forex-source, .quotes-details, .quotes-status, .forex-status { background: rgba(8,16,26,.92); border-radius: 8px; padding: 6px 10px; width: fit-content; max-width: 100%; margin-inline: auto; }
.quotes-source:empty { display: none; }

/* The phrase stays at the bottom; rates reserve its measured height and scroll independently. */
.ambient-phrase {
  position: fixed;
  left: 50%;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + var(--media-credit-space, 0px) + var(--footer-status-space, 0px));
  transform: translateX(-50%);
  width: min(640px, calc(100% - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right))));
  max-height: 40dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(9, 16, 27, 0.28);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
  text-shadow: 0 1px 3px #000, 0 1px 10px #000;
}
.ambient-content {
  bottom: calc(var(--content-bottom) + var(--media-credit-space, 0px) + var(--footer-status-space, 0px) + var(--phrase-footer-space, 0px));
}
@media (max-width: 600px) { .quote-value, #forex-card .forex-value { font-size: clamp(2rem,16vw,5rem); } }

.settings-panel .rate-source-picker { justify-content: flex-start; }


/* Price movement is encoded on the number itself, at the displayed precision. */
.quote-value { color: #edf2f7; }
.quote-value[data-direction="up"] { color: #b4df91; }
.quote-value[data-direction="down"] { color: #ffabab; }

.live-viewers { position: fixed; left: max(12px,env(safe-area-inset-left)); bottom: max(8px,env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 5px; max-width: calc(100% - 24px); font-size: .75rem; line-height: 1.4; color: #d8e0eb; text-shadow: 0 1px 3px #000,0 1px 8px #000; z-index: 5; }
.live-viewers svg { flex: 0 0 auto; filter: drop-shadow(0 1px 2px #000); }
.live-viewers__count { font-variant-numeric: tabular-nums; }
.live-viewers[hidden] { display: none; }
.media-attribution { bottom: calc(max(8px,env(safe-area-inset-bottom)) + var(--footer-status-space,0px)); }
.ambient-content { bottom: calc(var(--content-bottom) + var(--media-credit-space,0px) + var(--footer-status-space,0px) + var(--phrase-footer-space,0px)); }
/* Four instruments share the same visual language and reserve space for phrases. */
@media (min-width: 900px) {
  .quotes-list.quotes-list--oil { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 16px; }
  .quotes-list--oil .quote-value { font-size: clamp(1.65rem,4.5vw,5rem); }
}
@media (max-width: 899px) and (max-height: 740px) {
  .quotes-list--oil { gap: 14px; margin-block: 10px; }
  .quotes-list--oil .quote-value { font-size: clamp(1.8rem,10vw,3rem); }
}
