:root {
  --bg: #fff8ff;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --ink: #2f2940;
  --muted: #736987;
  --line: rgba(132, 103, 166, 0.2);
  --violet: #8a68c8;
  --violet-dark: #5b438b;
  --gold: #dcb768;
  --pink: #e998c7;
  --blue: #7aa5d8;
  --green: #6db8a6;
  --danger: #c25772;
  --shadow: 0 18px 50px rgba(79, 54, 119, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.56), rgba(255, 248, 255, 0.92)),
    url("/assets/backgrounds/lumi_landscape.png") center / cover fixed;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: max(12px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: 1180px;
  margin: 0 auto 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 10px 30px rgba(75, 51, 111, 0.1);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  align-items: center;
  min-width: 175px;
  padding: 8px 10px;
  color: var(--ink);
  border: 0;
  border-radius: 14px;
  background: transparent;
  text-align: left;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #f7d98e, #d6b1ff);
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-button,
.lumi-button,
.chip,
.icon-button {
  border: 1px solid rgba(108, 78, 146, 0.18);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.tab-button {
  flex: 0 0 auto;
  padding: 9px 13px;
  border-radius: 999px;
  white-space: nowrap;
}

.tab-button.active,
.lumi-button.primary,
.chip.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--violet), #bf83d7);
}

.tab-button:hover,
.lumi-button:hover,
.chip:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.app-main {
  max-width: 1180px;
  margin: 0 auto;
}

.loading-screen {
  display: grid;
  min-height: 58vh;
  place-items: center;
  padding: 40px 16px;
  text-align: center;
}

.loading-screen .moon {
  font-size: 48px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel.pad {
  padding: 16px;
}

.section-title {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.2;
}

.section-subtitle {
  margin: 0 0 14px;
  color: var(--muted);
}

.sidebar {
  align-self: start;
  max-height: calc(100vh - 108px);
  overflow: auto;
  padding: 12px;
}

.category {
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.category:last-child {
  border-bottom: 0;
}

.category-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 9px 8px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--violet-dark);
  font-weight: 700;
  text-align: left;
}

.category-title.active {
  background: rgba(245, 235, 255, 0.96);
}

.category-guide {
  margin: 8px 4px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
}

.custom-builder {
  padding: 2px 4px 0;
}

.spread-list {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.spread-button {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  text-align: left;
}

.spread-button.active {
  border-color: rgba(138, 104, 200, 0.65);
  background: rgba(246, 237, 255, 0.95);
}

.spread-button small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.reading-panel {
  display: grid;
  gap: 14px;
}

.single-reading-panel {
  max-width: 920px;
  margin: 0 auto;
}

.reading-empty {
  min-height: 270px;
  align-content: center;
}

.moon-symbol {
  margin-bottom: 8px;
  font-size: 38px;
}

.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(260px, 0.95fr);
  gap: 16px;
  padding: 16px;
}

.layout-preview {
  min-height: 240px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(138, 104, 200, 0.18);
  background: rgba(255, 255, 255, 0.52);
}

.layout-preview img,
.result-image {
  display: block;
  width: 100%;
  height: auto;
}

.layout-loading {
  display: grid;
  min-height: 240px;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.bottom-back {
  grid-column: 1 / -1;
  justify-self: start;
}

.guide {
  max-height: 280px;
  overflow: auto;
  margin-top: 10px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
  color: #443858;
  white-space: pre-wrap;
}

.flow-header {
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.back-link {
  margin: 0 0 10px;
  padding: 0;
  border: 0;
  color: var(--violet-dark);
  background: transparent;
  font-weight: 700;
}

.form-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--violet-dark);
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid rgba(108, 78, 146, 0.22);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 112px;
  padding: 12px;
  resize: vertical;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(138, 104, 200, 0.12);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.lumi-button {
  min-height: 42px;
  padding: 9px 13px;
  border-radius: 14px;
  font-weight: 700;
}

.lumi-button.secondary {
  background: rgba(255, 255, 255, 0.82);
}

.lumi-button.danger {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #c25772, #dd8a9d);
}

.lumi-button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 36px;
  padding: 7px 12px;
  border-radius: 999px;
  font-weight: 700;
}

.questions,
.reviewed,
.result-text {
  white-space: pre-wrap;
}

.questions,
.reviewed {
  padding: 12px;
  border-radius: 14px;
  background: rgba(247, 238, 255, 0.8);
}

.result {
  display: grid;
  gap: 14px;
}

.result-top {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
}

.card-list,
.stat-grid,
.plan-grid,
.admin-grid {
  display: grid;
  gap: 10px;
}

.mini-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.mini-card strong {
  display: block;
  margin-bottom: 4px;
}

.cards-table {
  width: 100%;
  border-collapse: collapse;
}

.cards-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.cards-table td:first-child {
  width: 34px;
  color: var(--violet-dark);
  font-weight: 800;
}

.result-text {
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid-select {
  display: grid;
  grid-template-columns: repeat(5, 52px);
  gap: 8px;
  margin: 8px 0 12px;
}

.grid-select button {
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--violet-dark);
  font-weight: 800;
}

.grid-select button.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--violet), var(--pink));
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(48, 39, 67, 0.94);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.loader {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(45, 34, 68, 0.24);
  backdrop-filter: blur(10px);
}

.loader[hidden] {
  display: none;
}

.loader-panel {
  width: min(460px, 100%);
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.loader-title {
  margin-bottom: 10px;
  color: var(--violet-dark);
  font-weight: 800;
}

.progress {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(138, 104, 200, 0.14);
}

.progress div {
  width: 3%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--violet), var(--gold), var(--green));
  transition: width 0.45s ease;
}

.loader-percent {
  margin: 8px 0;
  color: var(--muted);
  font-weight: 700;
}

.loader-note {
  color: #514568;
}

.audio-box audio {
  width: 100%;
  margin-top: 8px;
}

.empty {
  padding: 22px;
  border: 1px dashed rgba(108, 78, 146, 0.24);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  body {
    background-image:
      linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 248, 255, 0.95)),
      url("/assets/backgrounds/lumi_portrait.png");
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace,
  .hero-card,
  .result-top,
  .two-col {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: none;
  }

  .brand {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  .panel.pad,
  .hero-card {
    padding: 12px;
  }

  .section-title {
    font-size: 18px;
  }

  .tab-button {
    padding: 8px 11px;
  }
}
