:root {
    color-scheme: light;
    --bg: #f6f7fb;
    --ink: #1d2333;
    --muted: #5f6b7a;
    --panel: #ffffff;
    --border: rgba(31, 41, 55, 0.12);
    --accent: #2563eb;
    --success: #16a34a;
    --danger: #ef4444;
    --warning: #f59e0b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--ink);
}

.is-hidden {
    display: none;
}

.app {
    max-width: 980px;
    margin: 0 auto;
    padding: 16px 16px 28px;
    min-height: 100dvh;
}

.app-header {
    text-align: center;
    margin-bottom: 14px;
}

.title {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
}

.title-mode {
    margin-left: 6px;
    font-size: 16px;
    font-weight: 600;
    color: var(--muted);
}

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

.app-main {
    display: grid;
    gap: 12px;
}

.app:not([data-mode]) .target-panel,
.app:not([data-mode]) .card-panel,
.app:not([data-mode]) .action-panel {
    display: none;
}

.target-panel,
.mode-panel,
.card-panel,
.action-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.panel-label {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 10px;
}

.target-card {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    border: 2px dashed rgba(37, 99, 235, 0.45);
    border-radius: 14px;
    background: linear-gradient(180deg, #f3f6ff 0%, #ffffff 100%);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08) inset;
}

.target-card .card {
    width: min(280px, 100%);
}

.rule-text {
    margin-top: 10px;
    color: var(--muted);
    font-size: 14px;
}

.app[data-mode="find-rule"] .card-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(6px, 1vw, 10px);
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.mode-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    background: #ffffff;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 6px;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.mode-card:hover {
    transform: translateY(-2px);
    border-color: rgba(37, 99, 235, 0.4);
    box-shadow: 0 12px 20px rgba(37, 99, 235, 0.12);
}

.mode-card__title {
    font-size: 16px;
    font-weight: 700;
}

.mode-card__desc {
    font-size: 13px;
    color: var(--muted);
}

.selection-info {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 12px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-cols, 4), minmax(0, 1fr));
    gap: 10px;
}

.card {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #ffffff;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 5 / 3;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, opacity 0.2s ease;
}

.card.selectable {
    cursor: pointer;
}

.card.selectable:hover {
    transform: translateY(-2px);
    border-color: rgba(37, 99, 235, 0.4);
    box-shadow: 0 12px 20px rgba(37, 99, 235, 0.15);
}

.card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
    transform: translateY(-2px) scale(1.02);
}

.card.correct {
    border-color: var(--success);
    background: rgba(22, 163, 74, 0.08);
}

.card.wrong {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
}

.card.missed {
    border-color: var(--warning);
    background: rgba(245, 158, 11, 0.12);
}

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

.symbols {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 0.8vw, 10px);
    width: 100%;
    height: 100%;
}

.symbol-svg {
    height: 78%;
    width: auto;
    max-width: 46%;
}

.card[data-count="2"] .symbol-svg {
    max-width: 42%;
}

.card[data-count="3"] .symbol-svg {
    max-width: 32%;
}

.card.pulse {
    animation: selectPulse 180ms ease;
}

.card.deal-hidden {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
}

.card.deal-in {
    opacity: 1;
    transform: translateY(0) scale(1);
}

@keyframes selectPulse {
    0% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-2px) scale(1.03); }
    100% { transform: translateY(0) scale(1); }
}

.action-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: center;
}

.primary-btn,
.secondary-btn {
    border: none;
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 16px;
    cursor: pointer;
    width: 100%;
}

.primary-btn {
    background: var(--accent);
    color: #ffffff;
}

.primary-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.secondary-btn {
    background: rgba(37, 99, 235, 0.12);
    color: var(--accent);
}

.feedback {
    grid-column: 1 / -1;
    font-size: 14px;
    color: var(--muted);
    text-align: center;
    min-height: 20px;
}

.rule-guess {
    margin-top: 14px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
    display: none;
    gap: 10px;
}

.rule-guess.is-visible {
    display: grid;
}

.rule-guess__header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.rule-guess__title {
    font-size: 14px;
    font-weight: 700;
}

.rule-guess__summary {
    font-size: 13px;
    color: var(--muted);
}

.rule-guess__grid {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.rule-dimension {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(37, 99, 235, 0.04);
    white-space: nowrap;
}

.rule-dimension.is-disabled {
    opacity: 0.55;
}

.rule-dimension__label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 14px;
}

.rule-dimension__relations {
    display: inline-flex;
    gap: 10px;
    flex-wrap: nowrap;
}

.rule-operator {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.02);
    flex-wrap: wrap;
}

.rule-operator.is-hidden {
    display: none;
}

.rule-operator__label {
    font-size: 13px;
    color: var(--muted);
}

.rule-operator__options {
    display: flex;
    gap: 12px;
    flex-wrap: nowrap;
}

.rule-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

@media (max-width: 640px) {
    .app {
        padding: 16px 12px 22px;
    }
}
