/* ============================================================
   SENARIUS Rules Page — Newspaper-Style Daily Puzzle Theme
   ============================================================
   Inherits theme variables from styles.css via :root.
   ============================================================ */

/* ── Body override for rules (align top) ──────────────────── */
body {
    font-family: var(--font-body);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Rules Container ──────────────────────────────────────── */
.rules-container {
    max-width: 680px;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    padding: var(--sp-xl) var(--sp-lg);
    color: var(--text);
    line-height: 1.55;
    position: relative;
    margin-top: 20px;
    margin-bottom: 20px;
}

/* ── Rules Header ─────────────────────────────────────────── */
.rules-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.rules-header h1 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--sp-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-sm);
}

/* Logo tiles on rules page — match main page */
.rules-header .logo-grid {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 3px;
    flex-wrap: nowrap;
}

.rules-header .logo-row {
    display: flex;
    gap: 3px;
    justify-content: center;
}

.rules-header .logo-tile {
    aspect-ratio: 1;
    width: 34px;
    min-height: 34px;
    border: 2px solid var(--text);
    border-radius: var(--r-sm);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 800;
    font-family: var(--font-heading);
    color: var(--text);
    text-shadow: none;
    transition: background 0.15s ease, transform 0.15s ease;
    position: relative;
    overflow: visible;
}

/* Clean two-tone alternating */
.rules-header .logo-tile:nth-child(odd) {
    background: var(--text);
    color: var(--surface);
}
.rules-header .logo-tile:nth-child(even) {
    background: var(--surface);
    color: var(--text);
}

.rules-header .logo-row:nth-child(2) .logo-tile:nth-child(odd) {
    background: var(--surface);
    color: var(--text);
}
.rules-header .logo-row:nth-child(2) .logo-tile:nth-child(even) {
    background: var(--text);
    color: var(--surface);
}

/* Remove old animations */
.rules-header .logo-tile::before { display: none; }

.rules-header .logo-tile:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ── Back Button ──────────────────────────────────────────── */
.back-btn {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--bg);
    color: var(--muted);
    text-decoration: none;
    padding: 9px 14px;
    border-radius: var(--r-md);
    font-weight: 500;
    transition: all 0.15s ease;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    font-family: var(--font-btn);
}

.back-btn:hover {
    background: var(--text);
    color: var(--surface);
    border-color: var(--text);
    text-decoration: none;
    transform: translateY(-1px);
}

.back-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Rules Content ────────────────────────────────────────── */
.rules-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ── Rule Sections ────────────────────────────────────────── */
.rule-section {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: var(--sp-lg);
    border-radius: var(--r-md);
    border-left: 4px solid var(--text);
}

.rule-section h2 {
    color: var(--text);
    font-size: 1.3rem;
    margin-bottom: var(--sp-md);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-family: var(--font-heading);
    letter-spacing: -0.01em;
}

.rule-section p {
    color: var(--text);
    line-height: 1.6;
    font-size: 0.92rem;
    font-weight: 400;
}

.rule-section ul {
    margin: var(--sp-md) 0;
    padding-left: 20px;
}

.rule-section li {
    color: var(--text);
    margin: 6px 0;
    line-height: 1.55;
    font-size: 0.88rem;
    font-weight: 400;
}

.rule-section strong {
    color: var(--text);
    font-weight: 600;
}

/* ── Example Grid (if present) ────────────────────────────── */
.example-grid {
    background: var(--surface);
    border: 2px solid var(--text);
    border-radius: var(--r-sm);
    padding: 0;
    margin: var(--sp-md) 0;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0;
    max-width: 240px;
    overflow: hidden;
}

.example-cell {
    aspect-ratio: 1;
    border-radius: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--text);
    min-height: 28px;
}

.example-cell.green {
    background: var(--player1);
    color: #ffffff;
}

.example-cell.blue {
    background: var(--player2);
    color: #ffffff;
}

.highlight {
    background: rgba(58, 125, 68, 0.15);
    padding: 2px 4px;
    border-radius: var(--r-sm);
    font-weight: 600;
}

/* ── Rule Steps ───────────────────────────────────────────── */
.rule-steps {
    display: flex;
    flex-direction: column;
    gap: var(--sp-md);
}

.step {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-md);
    padding: var(--sp-md);
    background: var(--surface);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
}

.step-number {
    display: none;
}

.step-content h3 {
    color: var(--text);
    font-size: 1.05rem;
    margin-bottom: var(--sp-sm);
    font-weight: 600;
    font-family: var(--font-heading);
}

.step-content p {
    color: var(--text);
    line-height: 1.55;
    font-size: 0.88rem;
    margin: 0;
}

/* ── Rule Grid (Valid / Invalid) ──────────────────────────── */
.rule-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: var(--sp-md);
}

.rule-box {
    padding: 18px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface);
}

.rule-box.valid {
    border-left: 4px solid var(--player1);
}

.rule-box.invalid {
    border-left: 4px solid var(--danger);
}

.rule-box h4 {
    color: var(--text);
    font-size: 0.95rem;
    margin-bottom: 12px;
    font-weight: 600;
    font-family: var(--font-heading);
}

.rule-box ul {
    margin: 0;
    padding-left: 16px;
}

.rule-box li {
    font-size: 0.85rem;
    margin: 4px 0;
}

/* ── Winning Conditions ───────────────────────────────────── */
.winning-conditions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-md);
    margin-top: var(--sp-md);
}

.condition {
    padding: var(--sp-md);
    background: var(--surface);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
}

.condition h4 {
    color: var(--text);
    font-size: 0.95rem;
    margin-bottom: var(--sp-sm);
    font-weight: 600;
    font-family: var(--font-heading);
}

.condition p {
    font-size: 0.85rem;
    margin: 0;
}

/* ── Tips ──────────────────────────────────────────────────── */
.tips {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tip {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    background: var(--surface);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
}

.tip-icon {
    font-size: 1.2rem;
    margin-top: 2px;
}

.tip p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.55;
}

/* ── Rules Footer ─────────────────────────────────────────── */
.rules-footer {
    text-align: center;
    margin-top: var(--sp-xl);
    padding-top: var(--sp-lg);
    border-top: 1px solid var(--border);
}

.play-now-btn {
    background: var(--text);
    color: var(--surface);
    border: none;
    padding: 14px 28px;
    border-radius: var(--r-md);
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-btn);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    text-decoration: none;
    display: inline-block;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.play-now-btn:hover {
    background: #333;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: var(--surface);
}

.play-now-btn:active {
    transform: translateY(0);
}

.play-now-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Responsive: Tablet ───────────────────────────────────── */
@media (max-width: 768px) {
    body {
        padding: 12px;
        align-items: flex-start;
    }

    .rules-container {
        padding: var(--sp-lg) 20px;
        border-radius: var(--r-md);
        margin-top: 10px;
        margin-bottom: 10px;
    }

    .rules-header {
        margin-bottom: 28px;
    }

    .rules-header .logo-tile {
        font-size: 0.9rem;
        min-height: 28px;
        width: 28px;
    }

    .rule-section {
        padding: 20px;
    }

    .rule-section h2 {
        font-size: 1.2rem;
        margin-bottom: 12px;
    }

    .rule-section p {
        font-size: 0.88rem;
    }

    .rule-section li {
        font-size: 0.85rem;
    }

    .example-grid {
        max-width: 200px;
    }

    .example-cell {
        font-size: 0.75rem;
        min-height: 24px;
    }

    .back-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .rule-grid {
        grid-template-columns: 1fr;
        gap: var(--sp-md);
    }

    .winning-conditions {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .step {
        padding: 14px;
        gap: 14px;
    }

    .step-content h3 {
        font-size: 1rem;
    }

    .step-content p {
        font-size: 0.85rem;
    }

    .condition {
        padding: 14px;
    }

    .tip {
        padding: 12px;
        gap: 10px;
    }

    .tip p {
        font-size: 0.85rem;
    }

    .play-now-btn {
        padding: 12px 24px;
        font-size: 0.95rem;
    }
}

/* ── Responsive: Small Phone ──────────────────────────────── */
@media (max-width: 480px) {
    .rules-container {
        padding: 20px var(--sp-md);
        max-width: 100%;
    }

    .rules-header .logo-tile {
        font-size: 0.75rem;
        min-height: 22px;
        width: 22px;
    }

    .rule-section {
        padding: 14px;
    }

    .rule-section h2 {
        font-size: 1.1rem;
    }

    .rule-section p {
        font-size: 0.8rem;
    }

    .rule-section li {
        font-size: 0.75rem;
    }

    .example-grid {
        max-width: 160px;
    }

    .example-cell {
        font-size: 0.65rem;
        min-height: 20px;
    }

    .back-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
        position: static;
        margin-bottom: var(--sp-md);
        display: inline-block;
    }

    .rules-header {
        text-align: center;
        position: relative;
    }

    .step {
        padding: 12px;
        flex-direction: column;
        text-align: center;
    }

    .condition {
        padding: 12px;
    }

    .tip {
        padding: 10px;
        flex-direction: column;
        text-align: center;
    }

    .tip-icon {
        font-size: 1.5rem;
        margin-bottom: 4px;
    }

    .play-now-btn {
        width: 100%;
        max-width: 280px;
        padding: 14px 20px;
    }
}

/* ── Responsive: Very Small ───────────────────────────────── */
@media (max-width: 360px) {
    .rules-container {
        padding: 18px 14px;
    }

    .rules-header .logo-tile {
        font-size: 0.7rem;
        min-height: 20px;
        width: 20px;
    }

    .rule-section {
        padding: 12px;
    }

    .rule-section h2 {
        font-size: 1rem;
        flex-direction: column;
        gap: 6px;
        text-align: center;
    }

    .rule-section p {
        font-size: 0.75rem;
    }

    .rule-section li {
        font-size: 0.7rem;
    }

    .example-grid {
        max-width: 140px;
    }

    .example-cell {
        font-size: 0.6rem;
        min-height: 18px;
    }

    .rules-header h1 {
        font-size: 1rem;
    }
}

/* ── Dark Mode ────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    body {
        background: var(--bg);
        color: var(--text);
    }

    .rules-container {
        background: var(--surface);
        border-color: var(--border);
        color: var(--text);
    }

    .rules-header {
        border-bottom-color: var(--border);
    }

    .rules-header .logo-tile {
        border-color: var(--text);
    }

    .rules-header .logo-tile:nth-child(odd) {
        background: var(--text);
        color: var(--surface);
    }
    .rules-header .logo-tile:nth-child(even) {
        background: var(--surface);
        color: var(--text);
    }

    .rules-header .logo-row:nth-child(2) .logo-tile:nth-child(odd) {
        background: var(--surface);
        color: var(--text);
    }
    .rules-header .logo-row:nth-child(2) .logo-tile:nth-child(even) {
        background: var(--text);
        color: var(--surface);
    }

    .back-btn {
        background: var(--bg);
        color: var(--muted);
        border-color: var(--border);
    }

    .back-btn:hover {
        background: var(--text);
        color: var(--surface);
        border-color: var(--text);
    }

    .rule-section {
        background: var(--bg);
        border-color: var(--border);
        border-left-color: var(--text);
    }

    .rule-section h2,
    .rule-section p,
    .rule-section li,
    .rule-section strong {
        color: var(--text);
    }

    .example-grid {
        background: var(--surface);
        border-color: var(--text);
    }

    .example-cell {
        background: var(--surface);
        border-color: var(--border);
        color: var(--text);
    }

    .example-cell.green {
        background: var(--player1);
        color: #ffffff;
    }

    .example-cell.blue {
        background: var(--player2);
        color: #ffffff;
    }

    .highlight {
        background: rgba(90, 173, 101, 0.15);
        color: var(--text);
    }

    .step {
        background: var(--bg);
        border-color: var(--border);
    }

    .step-content h3,
    .step-content p {
        color: var(--text);
    }

    .rule-box {
        border-color: var(--border);
        background: var(--bg);
    }

    .rule-box.valid {
        border-left-color: var(--player1);
    }

    .rule-box.invalid {
        border-left-color: var(--danger);
    }

    .rule-box h4,
    .rule-box li {
        color: var(--text);
    }

    .condition {
        background: var(--bg);
        border-color: var(--border);
    }

    .condition h4,
    .condition p {
        color: var(--text);
    }

    .tip {
        background: var(--bg);
        border-color: var(--border);
    }

    .tip p {
        color: var(--text);
    }

    .rules-footer {
        border-top-color: var(--border);
    }
}

/* ── Accessibility ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .rules-header .logo-tile {
        transition: none !important;
    }

    .rules-header .logo-tile:hover {
        transform: none !important;
    }
}

/* ── Print ────────────────────────────────────────────────── */
@media print {
    body {
        background: white;
        padding: 0;
    }

    .rules-container {
        background: white;
        box-shadow: none;
        border: 1px solid #000;
        max-width: 100%;
        padding: 20px;
    }

    .back-btn {
        display: none;
    }

    .rules-header .logo-tile {
        background: #ccc !important;
        color: #000 !important;
        text-shadow: none !important;
        border-color: #999 !important;
    }

    .rule-section {
        background: white;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .example-cell.green,
    .example-cell.blue {
        background: #eee !important;
        color: #000 !important;
    }

    .play-now-btn {
        background: #666 !important;
        color: white !important;
    }
}
