:root {
  --bg: #120c22;
  --panel: rgba(30, 21, 54, .94);
  --line: #3d3063;
  --text: #ece6f5;
  --muted: #bcb2d4;
  --gold: #e9cf93;
  --gold-strong: #f3dca6;
  --button-text: #23183b;
  --bottom: max(14px, env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px));
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body { color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
h1 { margin: 0 0 10px; font: normal 1.35rem/1.25 Georgia, "Times New Roman", serif; color: var(--gold); }

#stage { position: fixed; inset: 0; }
#table { display: block; width: 100%; height: 100%; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }

.bar {
  position: absolute; top: 0; left: 0; right: 0; padding: 12px 16px; pointer-events: none;
  background: linear-gradient(var(--bg), transparent);
}
.in-telegram .bar { display: none; }
.logo { font: 1.15rem Georgia, "Times New Roman", serif; color: var(--text); }
.logo b { font-weight: normal; color: var(--gold); }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 16px var(--bottom);
  border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; background: var(--panel);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .45); backdrop-filter: blur(6px);
  animation: rise .35s ease-out;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.spreads { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.spread {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto auto; column-gap: 10px; align-items: center;
  padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: rgba(18, 12, 34, .7);
  color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: border-color .2s, transform .2s;
}
.spread:active { transform: scale(.97); border-color: var(--gold); }
.spread.is-used { opacity: .55; }
.spread-icon { grid-row: 1 / 4; display: flex; flex-wrap: wrap; gap: 2px; width: 30px; align-content: center; justify-content: center; }
.spread-icon i { display: block; width: 8px; height: 13px; border-radius: 2px; background: var(--gold); opacity: .85; }
.spread-celtic .spread-icon i { width: 5px; height: 8px; }
.spread-name { font: 1rem Georgia, "Times New Roman", serif; color: var(--gold); line-height: 1.2; }
.spread-text { font-size: .78rem; color: var(--muted); line-height: 1.3; }
.spread-cost { font-size: .78rem; color: var(--gold-strong); font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
textarea {
  display: block; width: 100%; margin: 6px 0 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: rgba(18, 12, 34, .85); color: var(--text); font: inherit; resize: none;
}
textarea:focus { outline: none; border-color: var(--gold); }
.row { display: flex; gap: 10px; }
.row .button { flex: 1; }
.button {
  padding: 13px 18px; border: 0; border-radius: 999px; background: var(--gold); color: var(--button-text);
  font: 600 1rem system-ui, -apple-system, "Segoe UI", sans-serif; cursor: pointer;
}
.button:active { background: var(--gold-strong); }
.button.ghost { background: transparent; color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.link { padding: 0; border: 0; background: none; color: var(--gold); font: inherit; text-decoration: underline; cursor: pointer; }

.hint {
  position: absolute; left: 12px; right: 12px; bottom: var(--bottom); padding: 12px 16px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); text-align: center; color: var(--text);
  display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: center; align-items: center; animation: rise .3s ease-out;
}

.reading { max-height: 82%; display: flex; flex-direction: column; padding-top: 6px; transition: max-height .35s ease; }
.reading.is-peek { max-height: 34%; }
.handle {
  align-self: center; margin: 0 0 8px; padding: 14px 18px 6px; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .85rem; cursor: pointer; position: relative;
}
.handle::before {
  content: ""; position: absolute; top: 4px; left: 50%; width: 44px; height: 4px; margin-left: -22px;
  border-radius: 2px; background: var(--line);
}
.reading-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.cards { margin: 8px 0 12px; padding-left: 18px; color: var(--gold-strong); font-size: .92rem; }
.text p { margin: 0 0 12px; }
.writing { color: var(--muted); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .45; } }

.toast {
  position: absolute; top: 54px; left: 16px; right: 16px; padding: 12px 16px; border-radius: 12px;
  background: #3a2a63; border: 1px solid var(--gold); color: var(--text); text-align: center; animation: rise .3s ease-out;
}
.demo { margin: 12px 0 0; font-size: .85rem; color: var(--muted); text-align: center; }

.failure, .loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px; background: var(--bg); text-align: center;
}
.loading { gap: 22px; color: var(--muted); }
.loading-card {
  width: 70px; height: 120px; border-radius: 8px; border: 1.5px solid var(--gold);
  background: radial-gradient(circle, var(--gold) 0 3px, transparent 4px), repeating-linear-gradient(45deg, rgba(233, 207, 147, .14) 0 2px, transparent 2px 9px), #2b1e50;
  animation: turn 1.8s ease-in-out infinite;
}
@keyframes turn { 50% { transform: rotateY(180deg); } }

@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; width: 560px; margin-left: -280px; }
  .hint { left: 50%; right: auto; width: 520px; margin-left: -260px; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet, .hint, .toast { animation: none; }
  .loading-card { animation-duration: 3s; }
}
