/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #1c1917;
  --text-secondary: #78716c;
  --border: #e7e5e4;
  --primary: #292524;
  --primary-hover: #44403c;
  --accent: #b91c1c;
  --accent-light: #fef2f2;
  --yang: #1c1917;
  --yin: #78716c;
  --moving: #b91c1c;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

/* ── App Shell ── */
#app {
  width: 100%;
  max-width: 420px;
  min-height: 100dvh;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
}

#header {
  text-align: center;
  padding: 32px 0 24px;
}

#header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text);
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ── Phase Switching ── */
.phase {
  display: none;
  flex-direction: column;
  align-items: center;
  flex: 1;
}
.phase.active {
  display: flex;
}

/* ── Idle Screen ── */
.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 60px 0;
}

.hero-text {
  font-size: 1.125rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.8;
}

/* ── Domain Hexagram ── */
.domain-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.domain-number {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.domain-hexagram {
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
  padding: 12px 0;
  width: 120px;
  align-items: center;
}

.domain-hexagram .hexagram-line {
  height: 20px;
  max-width: 100px;
  opacity: 1;
  transform: none;
  animation: none;
}

.domain-hexagram .hexagram-line .line-visual {
  height: 4px;
  border-radius: 2px;
}

.domain-hexagram .hexagram-line .line-label {
  display: none;
}

.domain-name {
  font-size: 0.875rem;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.domain-name .symbol {
  font-size: 1rem;
}

/* ── Buttons ── */
.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 160px;
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled {
  background: var(--border);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: 24px;
}
.btn-secondary:hover { border-color: var(--text-secondary); }

/* ── Casting Screen ── */
.throw-header {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.coin-result {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  transition: transform 0.15s ease;
}
.coin-result.flicker {
  animation: flicker-pulse 0.1s ease-in-out infinite alternate;
}

@keyframes flicker-pulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.03); }
}

.coin-num {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.coin-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Hexagram Display ── */
.hexagram-display {
  display: flex;
  flex-direction: column-reverse;  /* bottom line first */
  gap: 6px;
  padding: 20px 0;
  width: 100%;
  align-items: center;
}

.hexagram-line {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 200px;
  height: 30px;
  opacity: 0;
  transform: translateY(10px);
  animation: line-enter 0.3s ease forwards;
}

@keyframes line-enter {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hexagram-line .line-visual {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--yang);
  transition: background 0.2s;
}

.hexagram-line.yang .line-visual {
  width: 100%;
}

.hexagram-line.yin .line-visual {
  width: 100%;
  background: linear-gradient(
    to right,
    var(--yin) 0%, var(--yin) 42%,
    transparent 42%, transparent 58%,
    var(--yin) 58%, var(--yin) 100%
  );
}

.hexagram-line.moving .line-visual {
  background: var(--moving);
}
.hexagram-line.moving.yin .line-visual {
  background: linear-gradient(
    to right,
    var(--moving) 0%, var(--moving) 42%,
    transparent 42%, transparent 58%,
    var(--moving) 58%, var(--moving) 100%
  );
}

.hexagram-line .line-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: 12px;
  white-space: nowrap;
}

.hexagram-line.moving .line-label {
  color: var(--accent);
}

.hint-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 8px;
  text-align: center;
}

/* ── Result Screen ── */
.result-section {
  width: 100%;
  margin-bottom: 28px;
}

.result-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hexagram-name {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.judgment {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.lines-section {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.line-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.line-item:last-child { border-bottom: none; }

.line-item .line-symbol {
  font-size: 1.125rem;
  margin-right: 10px;
  flex-shrink: 0;
}

.line-item .line-position {
  color: var(--text-secondary);
  margin-right: 8px;
  flex-shrink: 0;
  font-weight: 500;
}

.line-item .line-text {
  color: var(--text);
  line-height: 1.5;
}

.line-item.moving {
  background: var(--accent-light);
}
.line-item.moving .line-position {
  color: var(--accent);
}

/* Divider */
.divider {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* Toggle */
.toggle-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 0;
}

.toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.toggle-btn:hover {
  border-color: var(--text-secondary);
}
.toggle-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Arrow indicator between hexagrams ── */
.arrow-down {
  text-align: center;
  color: var(--text-secondary);
  font-size: 1.25rem;
  margin: 8px 0;
}

/* ── Responsive ── */
@media (min-width: 768px) {
  #app {
    max-width: 480px;
    padding: 0 24px;
  }
}
