:root {
  --gold: #c9a35c;
  --gold-dim: rgba(201, 163, 92, .38);
  --ink: #d9ccb6;
  --ink-dim: #9a8c78;
  --panel-w: 380px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #040206;
  color: var(--ink);
  font-family: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 40% 45%, transparent 35%, rgba(2, 1, 4, .55) 75%, rgba(2, 1, 4, .92) 100%);
}

/* ---------- панель толкования ---------- */

#panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  padding: 30px 30px 24px;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(120, 60, 20, .16), transparent 70%),
    linear-gradient(180deg, rgba(14, 8, 20, .82), rgba(6, 3, 10, .9));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-left: 1px solid var(--gold-dim);
  box-shadow: -30px 0 80px rgba(0, 0, 0, .6);
}

#panel::before {
  content: '';
  position: absolute;
  inset: 8px 8px 8px 7px;
  border: 1px solid rgba(201, 163, 92, .13);
  pointer-events: none;
}

#panel header { text-align: center; flex: none; }

.sigil {
  color: var(--gold);
  letter-spacing: .6em;
  margin-right: -.6em;
  font-size: 14px;
  opacity: .8;
}

h1 {
  margin: 6px 0 0;
  font-family: 'Cormorant SC', 'Cormorant Garamond', Georgia, serif;
  font-weight: 500;
  font-size: 40px;
  letter-spacing: .28em;
  margin-right: -.28em;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(255, 170, 70, .35);
}

.tag {
  margin: 0 0 18px;
  font-style: italic;
  color: var(--ink-dim);
  font-size: 16px;
}

#panel header::after,
#spread::before {
  content: '';
  display: block;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
}

#reading {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 2px 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

.fade { animation: rise .7s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

.intro {
  text-align: center;
  font-size: 19px;
  line-height: 1.55;
  color: var(--ink-dim);
  padding: 20px 8px;
}

.intro .glyph {
  display: block;
  font-size: 44px;
  color: var(--gold);
  opacity: .7;
  margin-bottom: 18px;
  text-shadow: 0 0 30px rgba(255, 160, 60, .5);
}

.card-head {
  display: flex;
  gap: 18px;
  align-items: center;
}

.thumb {
  flex: none;
  width: 104px;
  aspect-ratio: 500 / 862;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 0 1px rgba(201, 163, 92, .5), 0 10px 30px rgba(0, 0, 0, .7), 0 0 40px rgba(255, 150, 50, .14);
  filter: sepia(.25) brightness(.88);
}

.thumb.rev { transform: rotate(180deg); }

.pos {
  font-family: 'Cormorant SC', serif;
  font-size: 13px;
  letter-spacing: .16em;
  color: var(--ink-dim);
}

.name {
  margin: 4px 0 6px;
  font-size: 31px;
  line-height: 1.05;
  font-weight: 500;
  color: #f0e2c4;
}

.sub {
  font-size: 15px;
  font-style: italic;
  color: var(--ink-dim);
  line-height: 1.3;
}

.orient {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 10px 4px;
  font-family: 'Cormorant SC', serif;
  font-size: 13px;
  letter-spacing: .12em;
  color: var(--gold);
  border: 1px solid var(--gold-dim);
  border-radius: 20px;
}

.orient.rev { color: #c98a8a; border-color: rgba(201, 138, 138, .4); }

.kw {
  margin: 22px 0 12px;
  text-align: center;
  font-family: 'Cormorant SC', serif;
  font-size: 16px;
  letter-spacing: .1em;
  color: var(--gold);
}

.meaning {
  margin: 0;
  font-size: 20px;
  line-height: 1.5;
  color: var(--ink);
}

.meaning::first-letter {
  font-size: 2.5em;
  line-height: .8;
  float: left;
  padding: 6px 8px 0 0;
  color: var(--gold);
  font-family: 'Cormorant SC', serif;
}

.other {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px dashed rgba(201, 163, 92, .18);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink-dim);
  font-style: italic;
}

.other b { font-style: normal; font-weight: 500; color: #b5a58c; }

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

#spread { flex: none; padding-bottom: 6px; }

#spread h3 {
  margin: 14px 0 8px;
  font-family: 'Cormorant SC', serif;
  font-weight: 500;
  font-size: 14px;
  letter-spacing: .2em;
  color: var(--ink-dim);
  text-align: center;
}

#chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 116px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

#chips li {
  padding: 3px 10px 4px;
  font-size: 15px;
  border: 1px solid rgba(201, 163, 92, .22);
  border-radius: 20px;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color .25s, border-color .25s, background .25s;
  white-space: nowrap;
}

#chips li:hover { color: var(--ink); border-color: var(--gold-dim); }

#chips li.on {
  color: #f0e2c4;
  border-color: var(--gold);
  background: rgba(201, 163, 92, .12);
}

#chips li .r { color: #c98a8a; margin-left: 4px; font-size: 12px; }

/* расклад текстом — запрос, который можно унести в ИИ-чат */
#ask {
  margin-top: 10px;
  padding: 8px 10px 9px;
  border: 1px dashed rgba(201, 163, 92, .28);
  border-radius: 4px;
  background: rgba(0, 0, 0, .22);
}

#ask-text {
  max-height: 4.2em;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink-dim);
  user-select: text;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

#ask-copy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  margin-top: 8px;
  padding: 6px 10px 7px;
  font: 500 13px 'Cormorant SC', 'Cormorant Garamond', serif;
  letter-spacing: .16em;
  color: var(--gold);
  background: rgba(201, 163, 92, .07);
  border: 1px solid var(--gold-dim);
  border-radius: 3px;
  cursor: pointer;
  transition: all .3s;
}

#ask-copy:hover { color: #f3dfb0; border-color: var(--gold); }
#ask-copy.done { color: #cfe6c0; border-color: #86a878; }

footer { flex: none; padding-top: 14px; text-align: center; }

#count {
  font-style: italic;
  font-size: 16px;
  color: var(--ink-dim);
  margin-bottom: 10px;
}

#reset {
  width: 100%;
  padding: 11px 16px 12px;
  font: 500 16px 'Cormorant SC', 'Cormorant Garamond', serif;
  letter-spacing: .18em;
  color: var(--gold);
  background: linear-gradient(180deg, rgba(201, 163, 92, .1), rgba(201, 163, 92, .03));
  border: 1px solid var(--gold-dim);
  border-radius: 3px;
  cursor: pointer;
  transition: all .3s;
}

#reset:hover:not(:disabled) {
  color: #f3dfb0;
  border-color: var(--gold);
  box-shadow: 0 0 26px rgba(255, 160, 60, .22), inset 0 0 18px rgba(255, 160, 60, .08);
}

#reset:disabled { opacity: .4; cursor: default; }

/* ---------- подсказка и сообщения ---------- */

#hint, #toast {
  position: fixed;
  left: calc((100vw - var(--panel-w)) / 2);
  transform: translateX(-50%);
  pointer-events: none;
  font-style: italic;
  text-align: center;
  transition: opacity 1.2s;
}

#hint {
  bottom: 34px;
  font-size: 19px;
  color: rgba(230, 215, 190, .8);
  text-shadow: 0 0 18px rgba(255, 150, 50, .5);
  animation: breathe 4s ease-in-out infinite;
}

#hint.off { opacity: 0; animation: none; }

@keyframes breathe { 50% { opacity: .45; } }

#toast {
  top: 34px;
  font-size: 18px;
  color: var(--gold);
  opacity: 0;
  text-shadow: 0 0 18px rgba(0, 0, 0, .9);
}

#toast.on { opacity: 1; transition: opacity .4s; }

/* ---------- узкий экран: панель снизу ---------- */

@media (max-width: 980px) {
  #panel {
    top: auto;
    left: 0;
    width: auto;
    height: 46vh;
    padding: 14px 18px 14px;
    border-left: 0;
    border-top: 1px solid var(--gold-dim);
  }
  #panel::before { display: none; }
  .sigil, .tag { display: none; }
  h1 { font-size: 22px; margin: 0 0 8px; }
  #reading { padding-top: 12px; }
  .thumb { width: 70px; }
  .name { font-size: 24px; }
  .meaning { font-size: 17px; }
  .kw { margin: 12px 0 8px; font-size: 14px; }
  #chips { flex-wrap: nowrap; overflow-x: auto; max-height: none; }
  #count { display: inline; margin-right: 10px; }
  #hint, #toast { left: 50%; }
  #hint { bottom: calc(46vh + 14px); font-size: 16px; }
}

/* ---------- настройки ---------- */

#settings-btn, #collapse-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--ink-dim);
  background: none;
  border: 1px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: color .3s, border-color .3s, transform .5s;
}

#settings-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 6;
}

#settings-btn:hover { color: var(--gold); border-color: var(--gold-dim); transform: rotate(60deg); }

#settings-menu {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 7;
  padding: 12px 14px 14px;
  background: rgba(12, 7, 18, .96);
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .7), 0 0 30px rgba(255, 150, 50, .08);
  animation: rise .3s ease both;
}

#settings-menu .label {
  margin: 0 0 8px;
  font-family: 'Cormorant SC', serif;
  font-size: 13px;
  letter-spacing: .2em;
  color: var(--ink-dim);
  text-align: center;
}

#settings-menu .seg + .label { margin-top: 14px; }

.seg { display: flex; gap: 6px; }

.seg button {
  flex: 1;
  padding: 5px 14px 6px;
  font: 500 16px 'Cormorant Garamond', Georgia, serif;
  color: var(--ink-dim);
  background: none;
  border: 1px solid rgba(201, 163, 92, .22);
  border-radius: 20px;
  cursor: pointer;
  transition: color .25s, border-color .25s, background .25s;
}

.seg button:hover { color: var(--ink); border-color: var(--gold-dim); }
.seg button.on { color: #f0e2c4; border-color: var(--gold); background: rgba(201, 163, 92, .12); }

/* ---------- сворачивание панели ---------- */

#panel { transition: transform .55s cubic-bezier(.6, 0, .2, 1); }

#collapse-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2;
}

#collapse-btn:hover { color: var(--gold); border-color: var(--gold-dim); }

body.collapsed #panel { transform: translateX(105%); }

#mini {
  position: fixed;
  top: 16px;
  right: 58px;
  z-index: 5;
  display: flex;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity .4s, transform .4s;
}

body.collapsed #mini { opacity: 1; pointer-events: auto; transform: none; transition-delay: .3s; }

#mini button {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px 1px 11px;
  font: 500 13px 'Cormorant SC', 'Cormorant Garamond', serif;
  letter-spacing: .14em;
  color: var(--gold);
  background: rgba(12, 7, 18, .72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--gold-dim);
  border-radius: 20px;
  cursor: pointer;
  transition: color .3s, border-color .3s, box-shadow .3s, opacity .3s;
}

#mini button:hover:not(:disabled) { color: #f3dfb0; border-color: var(--gold); box-shadow: 0 0 22px rgba(255, 160, 60, .2); }
#mini button:disabled { opacity: .4; cursor: default; }

body.collapsed #hint, body.collapsed #toast { left: 50%; }
body.collapsed #toast { top: 66px; }

@media (max-width: 980px) {
  #collapse-btn { top: 6px; left: auto; right: 10px; }
  #spread h3 { display: none; }
  #spread::before { margin-bottom: 8px; }
  #ask { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 5px 5px 5px 10px; }
  #ask-text { flex: 1; min-width: 0; max-height: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
  #ask-copy { width: auto; flex: none; margin: 0; white-space: nowrap; }
  #collapse-btn svg { transform: rotate(90deg); }
  #expand-btn svg { transform: rotate(90deg); }
  body.collapsed #panel { transform: translateY(105%); }
  body.collapsed #hint { bottom: 30px; }
  #toast { top: 62px; }
  #mini button { padding: 0 12px 1px 9px; }
}
