/**
 * Typography Studio — Unified Components
 * All components use design tokens for consistency
 * Version: 2.0
 */

/* ============================================
   BASE STYLES
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-secondary);
    background: var(--bg-primary);
    overflow-x: hidden;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    font-weight: var(--font-medium);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
}

h1 {
    font-size: var(--text-6xl);
}

h2 {
    font-size: var(--text-5xl);
}

h3 {
    font-size: var(--text-4xl);
}

h4 {
    font-size: var(--text-3xl);
}

h5 {
    font-size: var(--text-2xl);
}

h6 {
    font-size: var(--text-xl);
}

p {
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
}

a {
    color: var(--accent-primary-hover);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

a:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

strong {
    color: var(--text-primary);
    font-weight: var(--font-semibold);
}

small {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* Lists */
ul,
ol {
    color: var(--text-secondary);
    padding-left: var(--space-6);
}

li {
    margin-bottom: var(--space-2);
}

/* ============================================
   NAVIGATION
   ============================================ */

.nav-global {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--nav-border);
    z-index: var(--z-fixed);
    transition: all var(--transition-base);
}

.nav-global.scrolled {
    height: var(--nav-height-scrolled);
    box-shadow: var(--shadow-md);
}

.nav-content {
    max-width: var(--container-2xl);
    height: 100%;
    margin: 0 auto;
    padding: 0 var(--space-10);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-logo {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    letter-spacing: var(--tracking-tight);
}

.nav-links {
    display: flex;
    gap: var(--space-8);
    list-style: none;
    align-items: center;
}

.nav-link {
    color: var(--nav-link-color);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    transition: color var(--transition-fast);
    position: relative;
}

.nav-link:hover,
.nav-link.active {
    color: var(--nav-link-hover);
}

.nav-link.active::after,
.nav-link[aria-current="page"]::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-primary);
}

/* Hamburger button */
.nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.nav-hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-tertiary);
    border-radius: 2px;
    transition: transform var(--transition-base), opacity var(--transition-fast);
}

.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-hamburger:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Mobile navigation drawer */
.mobile-nav {
    display: none;
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-default);
    flex-direction: column;
    padding: var(--space-4) var(--space-6);
    gap: var(--space-1);
    z-index: calc(var(--z-fixed) - 1);
}

.mobile-nav.open { display: flex; }

.mobile-nav-link {
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    transition: color var(--transition-fast), background var(--transition-fast);
    text-decoration: none;
}

.mobile-nav-link:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
    text-decoration: none;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--button-padding-y) var(--button-padding-x);
    font-size: var(--text-sm);
    font-weight: var(--button-font-weight);
    border-radius: var(--button-radius);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary,
.cta-button,
.cta-btn {
    background: var(--accent-primary);
    color: var(--text-inverse);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover,
.cta-button:hover,
.cta-btn:hover {
    background: var(--accent-primary-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-primary:active {
    background: var(--accent-primary-active);
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--text-primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-large {
    padding: var(--space-4) var(--space-8);
    font-size: var(--text-base);
}

.btn-small {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-xs);
}

.btn-full {
    width: 100%;
}

/* ============================================
   CARDS
   ============================================ */

.card,
.feature-card,
.game-card,
.brand-card,
.emotion-card,
.font-card,
.gestalt-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--card-radius);
    padding: var(--card-padding);
    box-shadow: var(--card-shadow);
    transition: all var(--transition-base);
}

.card:hover,
.feature-card:hover,
.game-card:hover {
    background: var(--bg-elevated-hover);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-interactive:hover,
.feature-card:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-accent-md);
}

.card-title {
    color: var(--text-primary);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-3);
}

.card-description {
    color: var(--text-tertiary);
    line-height: var(--leading-relaxed);
}

.card-icon {
    font-size: var(--text-6xl);
    color: var(--text-primary);
    margin-bottom: var(--space-6);
    display: block;
}

/* Card Grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--space-6);
}

.card-grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.card-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* ============================================
   FORMS
   ============================================ */

.form-group {
    margin-bottom: var(--space-6);
}

.form-label {
    display: block;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wider);
    color: var(--text-tertiary);
    margin-bottom: var(--space-2);
}

.form-input,
.control-group input,
.control-group select {
    width: 100%;
    padding: var(--input-padding-y) var(--input-padding-x);
    font-size: var(--text-base);
    font-family: var(--font-sans);
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--input-radius);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.form-input:hover {
    border-color: var(--border-strong);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-elevated-hover);
    box-shadow: 0 0 0 3px var(--border-focus);
}

.form-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
    opacity: 1;
}

.form-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--surface-disabled);
}

/* ============================================
   PANELS & SECTIONS
   ============================================ */

.panel,
.sidebar,
.term-sidebar {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--panel-radius);
    padding: var(--panel-padding);
    box-shadow: var(--shadow-sm);
}

.panel-header {
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-default);
    margin-bottom: var(--space-6);
}

.panel-title {
    color: var(--text-primary);
    font-weight: var(--font-semibold);
    font-size: var(--text-lg);
}

.panel-section {
    padding: var(--space-6) 0;
    border-bottom: 1px solid var(--border-default);
}

.panel-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* ============================================
   SECTION HEADERS
   ============================================ */

.section-header {
    margin-bottom: var(--space-16);
    text-align: center;
}

.section-label {
    display: inline-block;
    padding: var(--space-2) var(--space-4);
    background: rgba(99, 102, 241, 0.2);
    color: #c7d2fe;
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wider);
    margin-bottom: var(--space-4);
}

.section-title {
    font-size: var(--text-5xl);
    font-weight: var(--font-light);
    letter-spacing: var(--tracking-tight);
    margin-bottom: var(--space-4);
    line-height: var(--leading-tight);
    background: linear-gradient(135deg, #ffffff 0%, #d0d0d0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.section-description {
    font-size: var(--text-lg);
    color: var(--text-tertiary);
    line-height: var(--leading-relaxed);
    max-width: 700px;
    margin: 0 auto;
}

/* ============================================
   PAGE LAYOUT
   ============================================ */

.page-container {
    min-height: 100vh;
    padding-top: var(--nav-height);
    background: var(--bg-primary);
}

.page-wrapper {
    max-width: var(--container-2xl);
    margin: 0 auto;
    padding: var(--space-20) var(--space-10);
}

.back-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    margin-bottom: var(--space-8);
    transition: all var(--transition-fast);
}

.back-button:hover {
    color: var(--text-primary);
    transform: translateX(-4px);
}

/* ============================================
   TABLES
   ============================================ */

table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--border-medium);
    background: var(--bg-elevated);
}

table thead tr {
    background: var(--accent-primary);
    color: var(--text-inverse);
    font-weight: var(--font-semibold);
}

table th,
table td {
    padding: var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border-default);
}

table th {
    color: var(--text-inverse);
}

table td {
    color: var(--text-secondary);
}

table tbody tr {
    background: var(--bg-elevated);
    transition: background var(--transition-fast);
}

table tbody tr:nth-child(even) {
    background: var(--bg-secondary);
}

table tbody tr:hover {
    background: var(--bg-elevated-hover);
}

/* ============================================
   INTERACTIVE STATES
   ============================================ */

.term-card,
.toggle-btn,
.emotion-btn {
    background: var(--bg-elevated);
    border: 2px solid var(--border-medium);
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-base);
}

.term-card:hover,
.toggle-btn:hover,
.emotion-btn:hover {
    background: var(--bg-elevated-hover);
    border-color: var(--border-strong);
}

.term-card.selected,
.toggle-btn.active,
.emotion-btn.active,
.emotion-card.active {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border-color: var(--accent-primary);
}

.term-card.selected h3,
.toggle-btn.active h3 {
    color: var(--text-inverse);
}

.term-card.selected p {
    color: rgba(0, 0, 0, 0.7);
}

/* ============================================
   WORKSPACE & CANVAS
   ============================================ */

.workspace,
.canvas-workspace {
    background: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 100%);
    min-height: calc(100vh - var(--nav-height));
    padding: var(--space-16) var(--space-10);
    position: relative;
}

.workspace::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
    opacity: 0.5;
}

.workspace-canvas {
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-medium);
    position: relative;
    z-index: var(--z-base);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Text Colors */
.text-primary {
    color: var(--text-primary);
}

.text-secondary {
    color: var(--text-secondary);
}

.text-tertiary {
    color: var(--text-tertiary);
}

.text-muted {
    color: var(--text-muted);
}

/* Backgrounds */
.bg-elevated {
    background: var(--bg-elevated);
}

.bg-primary {
    background: var(--bg-primary);
}

/* Spacing */
.mt-4 {
    margin-top: var(--space-4);
}

.mt-6 {
    margin-top: var(--space-6);
}

.mt-8 {
    margin-top: var(--space-8);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

.mb-6 {
    margin-bottom: var(--space-6);
}

.mb-8 {
    margin-bottom: var(--space-8);
}

/* Display */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-4 {
    gap: var(--space-4);
}

.gap-6 {
    gap: var(--space-6);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1024px) {
    .card-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .page-wrapper {
        padding: var(--space-12) var(--space-6);
    }

    .card-grid,
    .card-grid-2,
    .card-grid-3 {
        grid-template-columns: 1fr;
    }

    .nav-links {
        display: none;
    }

    .nav-hamburger {
        display: flex;
    }

    .section-title {
        font-size: var(--text-4xl);
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

*:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Reduced motion — WCAG 2.3.3 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* ============================================
   PRINT
   ============================================ */

@media print {

    .nav-global,
    .back-button,
    .btn {
        display: none;
    }

    .page-container {
        padding-top: 0;
    }
}