:root {
  color-scheme: light;
  --page: #f3f5f7;
  --surface: #ffffff;
  --surface-alt: #f8fafb;
  --line: #d9e0e6;
  --line-strong: #bdc8d0;
  --text: #17212b;
  --muted: #6d7a84;
  --accent: #1f7a5c;
  --accent-dark: #155943;
  --danger: #8a4a00;
  --shadow: 0 16px 36px rgba(22, 34, 45, 0.10);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100%;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 360px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--text);
  color: #ffffff;
  font-weight: 800;
}

.brand-name {
  font-weight: 800;
}

.auth-panel h1 {
  margin: 22px 0 18px;
  font-size: 22px;
  line-height: 1.2;
}

.telegram-login {
  display: none;
}

.access-code-form {
  display: grid;
  gap: 8px;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.access-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.access-code-row input {
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  outline: none;
}

.access-code-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 92, 0.14);
}

.telegram-link-panel {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.auth-link {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  text-decoration: none;
}

.auth-note {
  min-height: 20px;
  margin: 16px 0 0;
  color: var(--danger);
  font-size: 14px;
  line-height: 1.4;
}

.workspace-view {
  height: 100vh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #eef2f4;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--line);
  background: #f7f9fa;
}

.label {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sidebar h2 {
  margin: 2px 0 0;
  font-size: 18px;
  line-height: 1.25;
}

.icon-button,
.primary-button,
.secondary-button {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.icon-button {
  width: 36px;
  background: var(--text);
  color: #ffffff;
  font-size: 23px;
  line-height: 1;
}

.primary-button {
  min-width: 124px;
  padding: 0 16px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.secondary-button {
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
  font-weight: 700;
}

.icon-button:hover,
.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-alt);
}

.reading-list {
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
}

.reading-item {
  width: 100%;
  display: grid;
  gap: 5px;
  padding: 11px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.reading-item:hover,
.reading-item.is-active {
  border-color: var(--line);
  background: var(--surface);
}

.reading-item__title,
.reading-item__meta,
.reading-item__preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reading-item__title {
  font-weight: 800;
}

.reading-item__meta,
.reading-item__preview {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.32;
}

.workspace-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface);
}

.workspace-header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.workspace-heading {
  min-width: 0;
}

.workspace-title {
  max-width: min(70vw, 900px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  font-weight: 850;
}

.workspace-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace-body {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 20px;
  background: var(--surface-alt);
}

.question-panel,
.cards-panel,
.answer-panel,
.followup-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-title {
  font-weight: 850;
}

.panel-body {
  padding: 14px;
}

.muted {
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
  line-height: 1.45;
}

.question-text {
  margin: 0;
  line-height: 1.5;
}

.answer-text {
  margin: 0;
  line-height: 1.58;
  white-space: pre-wrap;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-chip {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 9px;
  background: #f8fafb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 12px;
}

.tarot-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-alt);
}

.tarot-card img {
  width: 100%;
  display: block;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: #e4eaee;
}

.tarot-card__body {
  padding: 9px;
}

.tarot-card__title,
.tarot-card__position,
.tarot-card__orientation {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tarot-card__title {
  font-size: 13px;
  font-weight: 850;
}

.tarot-card__position,
.tarot-card__orientation {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.followup-list {
  display: grid;
  gap: 12px;
}

.followup-item {
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.followup-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.followup-question {
  font-weight: 800;
  line-height: 1.45;
}

.followup-answer {
  color: #24323d;
  line-height: 1.55;
  white-space: pre-wrap;
}

.notice {
  border-left: 3px solid var(--accent);
  padding: 10px 12px;
  background: #f0f7f4;
  color: #21342e;
  line-height: 1.45;
}

.loading-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s infinite ease-in-out;
}

.loading-dot:nth-child(2) {
  animation-delay: 120ms;
}

.loading-dot:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

.composer {
  display: grid;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.spread-selector {
  width: fit-content;
  display: grid;
  grid-template-columns: repeat(2, minmax(104px, 1fr));
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-alt);
}

.spread-option {
  min-height: 32px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.spread-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.spread-option:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(22, 34, 45, 0.12);
}

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.composer-row textarea {
  width: 100%;
  max-height: 148px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  outline: none;
  line-height: 1.35;
}

.composer-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 92, 0.14);
}

@media (max-width: 860px) {
  .workspace-view {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .workspace-header {
    align-items: flex-start;
    padding: 12px;
  }

  .workspace-title {
    max-width: 58vw;
  }

  .workspace-body {
    padding: 12px;
    gap: 12px;
  }

  .composer {
    padding: 12px;
  }

  .spread-selector {
    width: 100%;
  }

  .composer-row {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }
}
