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

:root {
    --color-primary:       #4f46e5;
    --color-primary-dark:  #3730a3;
    --color-primary-light: #e0e7ff;
    --color-bg:            #f8fafc;
    --color-surface:       #ffffff;
    --color-border:        #e2e8f0;
    --color-text:          #1e293b;
    --color-text-muted:    #64748b;
    --color-arena-bg:      #dbeafe;
    --color-arena-text:    #1e40af;
    --color-blind-bg:      #fee2e2;
    --color-blind-text:    #991b1b;
    --color-facade-bg:     #dcfce7;
    --color-facade-text:   #166534;
    --color-unknown-bg:    #f1f5f9;
    --color-unknown-text:  #475569;
    --shadow-sm:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
    --shadow-lg:   0 10px 15px rgba(0,0,0,.07), 0 4px 6px rgba(0,0,0,.05);
    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   16px;
    --font:        'Inter', system-ui, -apple-system, sans-serif;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   Layout helpers
   ============================================================ */
.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
}

/* ============================================================
   Header
   ============================================================ */
.site-header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: #fff;
    padding: 2.5rem 0 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

.site-header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.site-header .subtitle {
    margin-top: 0.4rem;
    font-size: 1.05rem;
    opacity: 0.85;
    font-weight: 400;
}

/* ============================================================
   Instructions card
   ============================================================ */
.instructions h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-primary-dark);
}

.instructions p {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

/* ============================================================
   Trait tables layout
   ============================================================ */
.tables-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .tables-grid {
        grid-template-columns: 1fr;
    }
}

.tables-grid .card {
    margin-bottom: 0;
    padding: 1.25rem;
}

/* ============================================================
   Trait tables
   ============================================================ */
#tableJohari,
#tableNohari {
    width: 100%;
    border-collapse: separate;
    border-spacing: 4px;
}

#tableJohari caption,
#tableNohari caption {
    font-size: 1.1rem;
    font-weight: 700;
    text-align: left;
    padding-bottom: 0.75rem;
    color: var(--color-text);
}

.caption-sub {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--color-text-muted);
}

#tableJohari tr td,
#tableNohari tr td {
    border: 1px solid var(--color-border);
    text-align: center;
    padding: 0.45rem 0.3rem;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    user-select: none;
    background: var(--color-bg);
    color: var(--color-text);
}

#tableJohari tr td:hover {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    border-color: var(--color-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

#tableNohari tr td:hover {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* Selected state */
#tableJohari tr td.selected {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary-dark);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

#tableNohari tr td.selected {
    background: #dc2626;
    color: #fff;
    border-color: #b91c1c;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* ============================================================
   Action bar
   ============================================================ */
.action-bar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.selection-hint {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

#calculateBtn {
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-family: var(--font);
    font-weight: 600;
    cursor: pointer;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    letter-spacing: 0.01em;
}

#calculateBtn:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

#calculateBtn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

/* ============================================================
   Outcome section
   ============================================================ */
.outcome-section {
    overflow: hidden;
}

.outcome-section h2.section-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--color-text);
}

#outcomeChart {
    width: 100%;
    height: 400px;
    table-layout: fixed;
    border-collapse: collapse;
}

#colLabel {
    width: 120px;
}

#colKnownSelf,
#colNotKnownSelf {
    width: calc((100% - 120px) / 2);
}

#outcomeChart th.axis-label,
#outcomeChart td {
    border: 2px solid var(--color-border);
    padding: 12px;
    vertical-align: top;
}

#outcomeChart thead tr {
    height: 40px;
}

#outcomeChart th.axis-label {
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
    background: var(--color-surface);
    color: var(--color-text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Top-row column headers (horizontal axis) */
#outcomeChart th.axis-label-col {
    border-bottom: 2px solid var(--color-primary);
}

/* Row headers (vertical axis) — rotate text so it reads upward */
#outcomeChart th.axis-label-row {
    vertical-align: middle;
    border-right: 2px solid var(--color-primary);
}

#outcomeChart th.axis-label-row span {
    display: inline-block;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
}

/* Top-left corner cell */
#outcomeChart th.axis-label-corner {
    border-right: 2px solid var(--color-primary);
    border-bottom: 2px solid var(--color-primary);
}

#outcomeChart ul {
    list-style-type: disc;
    padding-left: 20px;
    margin-top: 4px;
}

#outcomeChart ul li {
    font-size: 0.9rem;
    margin-bottom: 2px;
}

/* Quadrant label — top-left badge inside each quadrant cell */
.quadrant-title {
    font-size: 0.95rem;
    font-weight: 700;
    text-align: left;
    letter-spacing: 0.01em;
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid currentColor;
    opacity: 0.85;
}

.quadrant-sub {
    font-weight: 400;
    font-size: 0.8rem;
    opacity: 0.75;
}

/* Quadrant colours */
.arena {
    vertical-align: top;
    background: var(--color-arena-bg);
    color: var(--color-arena-text);
}

.blind {
    vertical-align: top;
    background: var(--color-blind-bg);
    color: var(--color-blind-text);
}

.facade {
    vertical-align: top;
    background: var(--color-facade-bg);
    color: var(--color-facade-text);
}

.unknown {
    vertical-align: top;
    background: var(--color-unknown-bg);
    color: var(--color-unknown-text);
}

/* ============================================================
   Chart container
   ============================================================ */
#chartContainer {
    max-width: 800px;
}

#chartContainer h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--color-text);
}

#mermaidChart svg {
    max-width: 100%;
    height: auto;
}

/* ============================================================
   Example section
   ============================================================ */
.example-section h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--color-text);
}

.example-section img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    display: block;
}

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 1.25rem 0;
    margin-top: auto;
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* ============================================================
   Main content spacing
   ============================================================ */
main.container {
    padding-top: 0.5rem;
    padding-bottom: 2rem;
    flex: 1;
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    #tableJohari tr td,
    #tableNohari tr td,
    #calculateBtn {
        transition: none;
        transform: none;
    }
}
