* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #1a1030;
    color: #f5f0e8;
}

#app {
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(160deg, #1a1030 0%, #2d1b4e 45%, #1a1030 100%);
    position: relative;
}

.embed-mode #app,
.embed-mode.history-page {
    min-height: auto;
}

.embed-mode .focus-column {
    min-height: auto;
}

.embed-mode .install-button,
.embed-mode #install-prompt,
.embed-mode #install-modal {
    display: none !important;
}

.focus-column {
    width: 100%;
    max-width: 28rem;
    margin: 0 auto;
    min-height: 100dvh;
    padding: 1.5rem 1rem 2.5rem;
    padding-top: max(1.5rem, calc(0.75rem + env(safe-area-inset-top)));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hero {
    text-align: center;
    margin-bottom: 1.5rem;
    width: 100%;
}

.hero h1 {
    font-size: clamp(1.75rem, 5vw, 2.25rem);
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #f5e6c8;
}

.subtitle {
    margin-top: 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
    color: rgba(245, 240, 232, 0.75);
}

.options-menu {
    position: relative;
}

.menu-toggle {
    position: fixed;
    top: max(0.75rem, env(safe-area-inset-top));
    right: max(0.75rem, env(safe-area-inset-right));
    z-index: 110;
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0;
    border: 1px solid rgba(212, 175, 55, 0.35);
    border-radius: 10px;
    background: rgba(26, 16, 48, 0.85);
    color: #f5e6c8;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: background 0.15s, border-color 0.15s;
}

.menu-toggle:hover {
    border-color: rgba(212, 175, 55, 0.55);
}

.menu-toggle:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.menu-toggle[aria-expanded="true"] .menu-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.menu-toggle[aria-expanded="true"] .menu-bar:nth-child(2) {
    opacity: 0;
}

.menu-toggle[aria-expanded="true"] .menu-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.menu-bar {
    display: block;
    width: 1.125rem;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    transition: opacity 0.2s ease;
}

.menu-backdrop.hidden {
    display: none;
}

.draw-settings {
    position: fixed;
    top: calc(max(0.75rem, env(safe-area-inset-top)) + 3.25rem);
    right: max(0.75rem, env(safe-area-inset-right));
    z-index: 105;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 11rem;
    padding: 1rem;
    background: rgba(26, 16, 48, 0.95);
    border: 1px solid rgba(212, 175, 55, 0.25);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(12px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.draw-settings.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(0.98);
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.setting-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(245, 240, 232, 0.55);
}

.option-group {
    display: flex;
    gap: 0.35rem;
    padding: 0.25rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(212, 175, 55, 0.15);
    border-radius: 10px;
}

.option {
    flex: 1;
    min-width: 2.5rem;
    padding: 0.45rem 0.6rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: rgba(245, 240, 232, 0.75);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: center;
}

.option.active {
    background: rgba(212, 175, 55, 0.25);
    color: #f5e6c8;
}

.option:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.menu-divider {
    height: 1px;
    background: rgba(212, 175, 55, 0.2);
    margin: 0.15rem 0;
}

.menu-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.menu-history-link {
    display: block;
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(212, 175, 55, 0.2);
    color: #f5e6c8;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.menu-history-link:hover {
    background: rgba(212, 175, 55, 0.15);
    border-color: rgba(212, 175, 55, 0.35);
}

.menu-site-link {
    display: block;
    padding: 0.2rem 0.5rem;
    color: rgba(245, 240, 232, 0.45);
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    transition: color 0.15s;
}

.menu-site-link:hover {
    color: rgba(245, 240, 232, 0.72);
}

.history-page .page-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: max(0.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.75rem max(1rem, env(safe-area-inset-left));
    background: rgba(26, 16, 48, 0.9);
    border-bottom: 1px solid rgba(212, 175, 55, 0.15);
    backdrop-filter: blur(10px);
}

.history-page .page-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #f5e6c8;
    letter-spacing: 0.04em;
}

.back-link {
    color: #d4af37;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.back-link:hover {
    text-decoration: underline;
}

.history-column {
    padding-top: calc(3.5rem + env(safe-area-inset-top));
    min-height: auto;
}

.history-empty {
    text-align: center;
    color: rgba(245, 240, 232, 0.65);
    line-height: 1.6;
    padding: 2rem 0;
}

.history-empty.hidden {
    display: none;
}

.history-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-entry {
    padding: 1rem 1.15rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(212, 175, 55, 0.25);
    border-radius: 14px;
    backdrop-filter: blur(8px);
}

.history-entry-header {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.85rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(212, 175, 55, 0.15);
}

.history-entry-header time {
    font-size: 0.95rem;
    font-weight: 600;
    color: #f5e6c8;
}

.history-meta {
    font-size: 0.8rem;
    color: rgba(245, 240, 232, 0.55);
}

.history-entry-cards {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.history-card-row + .history-card-row {
    padding-top: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.history-card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.6rem;
    margin-bottom: 0.4rem;
}

.history-card-position {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(245, 240, 232, 0.5);
}

.history-card-name {
    font-size: 1rem;
    font-weight: 600;
    color: #f5e6c8;
    flex: 1;
    min-width: 0;
}

.history-card-meaning {
    font-size: 0.9rem;
    line-height: 1.55;
    color: rgba(245, 240, 232, 0.85);
}

.secondary-button {
    width: 100%;
    margin-top: 1.5rem;
    padding: 0.75rem 1.25rem;
    border: 1px solid rgba(212, 175, 55, 0.35);
    border-radius: 12px;
    background: transparent;
    color: rgba(245, 240, 232, 0.75);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.secondary-button:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #f5e6c8;
}

.secondary-button.hidden {
    display: none;
}

.card-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    flex: 1;
    justify-content: center;
    width: 100%;
}

.stage-prompt {
    font-size: 0.95rem;
    color: rgba(245, 240, 232, 0.65);
    min-height: 1.5rem;
    text-align: center;
    max-width: 28rem;
}

.cards-container {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    padding: 0.25rem 0;
    -webkit-overflow-scrolling: touch;
}

.cards-container.cards-count-1 {
    overflow-x: visible;
}

.cards-container.cards-count-3,
.cards-container.cards-count-5 {
    position: relative;
    display: block;
    overflow: visible;
    margin-left: auto;
    margin-right: auto;
}

.cards-container.cards-count-3 {
    --card-w: min(120px, 28vw);
    --card-h: min(192px, 45vw);
    width: min(100%, 300px);
    height: max(280px, calc(var(--card-h) * 1.85));
}

.cards-container.cards-count-5 {
    --card-w: min(88px, 18vw);
    --card-h: min(141px, 29vw);
    width: min(100%, 340px);
    height: max(340px, calc(var(--card-h) * 2.9));
}

.cards-count-3 .tarot-card,
.cards-count-5 .tarot-card {
    position: absolute;
    flex-shrink: 0;
}

/* 3-card: top-left, center, bottom-right */
.cards-count-3 .tarot-card:nth-child(1) {
    top: 0;
    left: 0;
    z-index: 1;
}

.cards-count-3 .tarot-card:nth-child(2) {
    top: calc(50% - var(--card-h) / 2);
    left: calc(50% - var(--card-w) / 2);
    z-index: 2;
}

.cards-count-3 .tarot-card:nth-child(3) {
    bottom: 0;
    right: 0;
    z-index: 1;
}

/* 5-card: symmetric pentagram (center-based positions) */
.spread-star-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.spread-star-lines polyline {
    fill: none;
    stroke: rgba(212, 175, 55, 0.4);
    stroke-width: 1.25;
    vector-effect: non-scaling-stroke;
}

.cards-count-5 .tarot-card {
    z-index: 1;
}

.cards-count-5 .tarot-card[data-index='0'] {
    left: calc(50% - var(--card-w) / 2);
    top: calc(12% - var(--card-h) / 2);
}

.cards-count-5 .tarot-card[data-index='1'] {
    left: calc(86.1% - var(--card-w) / 2);
    top: calc(38.3% - var(--card-h) / 2);
}

.cards-count-5 .tarot-card[data-index='2'] {
    left: calc(72.4% - var(--card-w) / 2);
    top: calc(80.7% - var(--card-h) / 2);
}

.cards-count-5 .tarot-card[data-index='3'] {
    left: calc(27.6% - var(--card-w) / 2);
    top: calc(80.7% - var(--card-h) / 2);
}

.cards-count-5 .tarot-card[data-index='4'] {
    left: calc(13.9% - var(--card-w) / 2);
    top: calc(38.3% - var(--card-h) / 2);
}

.tarot-card {
    --card-inset: 0.5rem;
    --card-art-pad: 0.35rem;
    --card-name-h: 2.75rem;
    --card-name-size: 0.95rem;
    width: min(220px, 58vw);
    height: min(352px, 93vw);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.7s ease-in-out;
    border-radius: 12px;
    flex-shrink: 0;
}

.tarot-card.interactive {
    cursor: pointer;
}

.tarot-card.interactive:active {
    transform: scale(0.98);
}

.tarot-card.is-flipped {
    transform: rotateY(180deg);
}

.tarot-card.is-flipped.interactive:active {
    transform: rotateY(180deg) scale(0.98);
}

.tarot-card.is-shuffling {
    animation: shuffle-pulse 0.4s ease-in-out infinite alternate;
}

@keyframes shuffle-pulse {
    from { transform: scale(1) rotate(-1deg); }
    to { transform: scale(1.03) rotate(1deg); }
}

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.card-back {
    background: #2a1848;
    color: #d4af37;
    border: 2px solid #d4af37;
}

.card-back-pattern {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border: 8px solid #2a1848;
    border-radius: 8px;
}

.pattern-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.celestial {
    font-size: 1.25rem;
    opacity: 0.85;
}

.center-star {
    font-size: 2rem;
    opacity: 0.9;
}

.card-front {
    background: #f5f0e8;
    color: #1a1030;
    transform: rotateY(180deg);
    border: 2px solid rgba(26, 16, 48, 0.15);
}

.card-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    height: 100%;
    padding: var(--card-inset);
    box-sizing: border-box;
    text-align: center;
}

.card-art {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: var(--card-art-pad);
    overflow: hidden;
}

.card-art-inner {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.4s ease;
}

.card-art-inner.is-reversed {
    transform: rotate(180deg);
}

.card-art img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
}

.card-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0.25rem;
    box-sizing: border-box;
}

.card-fallback-meaning {
    font-size: 0.7rem;
    line-height: 1.35;
    color: rgba(26, 16, 48, 0.85);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 6;
    overflow: hidden;
    text-align: center;
}

.card-content.no-image .card-art {
    background: rgba(26, 16, 48, 0.06);
    border-radius: 8px;
}

.card-name {
    flex: 0 0 var(--card-name-h);
    height: var(--card-name-h);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 0;
    padding: 0 0.2rem;
    box-sizing: border-box;
    font-size: var(--card-name-size);
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.2;
    text-align: center;
    overflow: hidden;
    word-break: break-word;
}

.readings {
    width: 100%;
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.readings.hidden {
    display: none;
}

.reading-item {
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(212, 175, 55, 0.25);
    border-radius: 16px;
    backdrop-filter: blur(8px);
    animation: fade-in 0.5s ease;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.card-header h2 {
    font-size: 1.1rem;
    color: #f5e6c8;
    line-height: 1.35;
}

.badge {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    white-space: nowrap;
}

.badge.upright {
    background: rgba(100, 180, 140, 0.25);
    color: #9fd4b8;
    border: 1px solid rgba(100, 180, 140, 0.4);
}

.badge.reversed {
    background: rgba(212, 140, 80, 0.25);
    color: #e8b878;
    border: 1px solid rgba(212, 140, 80, 0.4);
}

.reading-meaning {
    line-height: 1.6;
    color: rgba(245, 240, 232, 0.9);
    margin-bottom: 1rem;
}

.full-meanings {
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

.full-meanings summary {
    cursor: pointer;
    color: #d4af37;
    margin-bottom: 0.75rem;
    user-select: none;
}

.meaning-block {
    margin-top: 0.75rem;
}

.meaning-block h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(245, 240, 232, 0.55);
    margin-bottom: 0.35rem;
}

.meaning-block p {
    line-height: 1.55;
    color: rgba(245, 240, 232, 0.8);
}

.primary-button {
    width: 100%;
    margin-top: 1.25rem;
    padding: 0.85rem 1.25rem;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #d4af37 0%, #b8922e 100%);
    color: #1a1030;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.primary-button:active {
    transform: scale(0.98);
}

.primary-button.hidden {
    display: none;
}

.install-button {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    padding: 0.65rem 1rem;
    border: 1px solid rgba(212, 175, 55, 0.5);
    border-radius: 999px;
    background: rgba(26, 16, 48, 0.9);
    color: #f5e6c8;
    font-size: 0.85rem;
    cursor: pointer;
    backdrop-filter: blur(8px);
    z-index: 100;
}

.install-button.hidden,
.install-modal.hidden {
    display: none;
}

.install-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 200;
}

.install-modal-content {
    background: #2d1b4e;
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 16px;
    padding: 1.5rem;
    max-width: 22rem;
    width: 100%;
}

.install-modal-content h3 {
    margin-bottom: 1rem;
    color: #f5e6c8;
}

.install-steps {
    margin: 0 0 1.25rem 1.25rem;
    line-height: 1.7;
    color: rgba(245, 240, 232, 0.85);
}

.install-close-button {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: 10px;
    background: #d4af37;
    color: #1a1030;
    font-weight: 600;
    cursor: pointer;
}

.cards-count-3 .tarot-card {
    --card-inset: 0.35rem;
    --card-art-pad: 0.25rem;
    --card-name-h: 2rem;
    --card-name-size: 0.65rem;
    width: var(--card-w);
    height: var(--card-h);
}

.cards-count-3 .center-star {
    font-size: 1.25rem;
}

.cards-count-3 .celestial {
    font-size: 0.85rem;
}

.cards-count-5 .tarot-card {
    --card-inset: 0.25rem;
    --card-art-pad: 0.15rem;
    --card-name-h: 1.5rem;
    --card-name-size: 0.55rem;
    width: var(--card-w);
    height: var(--card-h);
}

.cards-count-5 .card-back-pattern {
    padding: 0.5rem;
    border-width: 4px;
}

.cards-count-5 .center-star {
    font-size: 0.9rem;
}

.cards-count-5 .celestial {
    font-size: 0.65rem;
}

.cards-count-5 .card-fallback-meaning {
    font-size: 0.45rem;
    line-height: 1.25;
    -webkit-line-clamp: 4;
}

@media (min-width: 480px) {
    .focus-column {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    .cards-count-1 .tarot-card {
        --card-name-h: 3rem;
        width: 240px;
        height: 384px;
    }

    .cards-container.cards-count-3 {
        --card-w: 140px;
        --card-h: 224px;
        width: 340px;
        height: 420px;
    }

    .cards-container.cards-count-5 {
        --card-w: 100px;
        --card-h: 160px;
        width: 360px;
        height: 460px;
    }
}

@media (min-width: 720px) {
    .focus-column {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}
