:root {
    --primary: #007aff;
    /* iOS Blue */
    --primary-dark: #0056b3;
    --bg: #f2f2f7;
    /* iOS System Gray 6 */
    --card-bg: #ffffff;
    --text: #1c1c1e;
    /* iOS Label */
    --text-secondary: #3c3c4399;
    /* iOS Secondary Label */
    --border: #c6c6c8;
    /* iOS Separator */
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.08);
    --header-bg: rgba(255, 255, 255, 0.85);
    --note-bg: #eef7ff;
    --note-border: #007aff;
    --success: #34c759;
    --warning: #ffcc00;
    --danger: #ff3b30;
    --radius: 16px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --card-bg: #1c1c1e;
        /* iOS Gray 6 Dark */
        --text: #ffffff;
        --text-secondary: #ebebf599;
        --border: #38383a;
        --header-bg: rgba(28, 28, 30, 0.85);
        --note-bg: #1a2a44;
        --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    }
}

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

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding-top: calc(60px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    min-height: 100vh;
    overscroll-behavior-y: none;
    /* Handled by JS or custom implementation */
}

/* App Bar */
.app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(60px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    background: var(--header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.app-bar h1 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.app-bar p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

/* Cards / Sections */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background: transparent;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
}

.card-icon {
    transition: transform 0.3s ease;
    color: var(--text-secondary);
}

.card.expanded .card-icon {
    transform: rotate(180deg);
}

.card-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--card-bg);
}

.card.expanded .card-content {
    max-height: 2000px;
    /* Arbitrary large height */
}

.card-body {
    padding: 0 16px 16px 16px;
}

/* Typography & Elements */
.note {
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: var(--note-bg);
    padding: 12px;
    border-radius: 8px;
    border-left: 4px solid var(--note-border);
    margin-bottom: 16px;
}

.example {
    font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
    background: var(--bg);
    padding: 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text);
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

/* Tables */
.table-container {
    overflow-x: auto;
    margin: 0 -16px;
    /* Bleed to edges on small screens */
    padding: 0 16px;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9rem;
}

th,
td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--card-bg);
    position: sticky;
    top: 0;
}

td:first-child,
th:first-child {
    padding-left: 0;
}

td:last-child,
th:last-child {
    padding-right: 0;
}

tr:last-child td {
    border-bottom: none;
}

/* Calculator Inputs */
.input-group {
    margin-bottom: 16px;
}

.input-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-control {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    display: block;
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    color: white;
    background: var(--primary);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn:active {
    background: var(--primary-dark);
    transform: scale(0.98);
}

.result-box {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: 12px;
    text-align: center;
    font-weight: 600;
    border: 1px solid var(--border);
}

/* Pull to Refresh */
#pull-refresh {
    position: fixed;
    top: calc(60px + env(safe-area-inset-top));
    left: 0;
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-secondary);
    z-index: 900;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-100%);
    transition: opacity 0.2s;
}

#pull-refresh.visible {
    opacity: 1;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-secondary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Utilities */
.text-center {
    text-align: center;
}

.mb-2 {
    margin-bottom: 8px;
}

.mt-2 {
    margin-top: 8px;
}

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

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