:root {
    --primary: #1e3a8a;
    --primary-light: #eff6ff;
    --accent: #15803d;
    --minibus: #92400e;
    --minibus-bg: #fef3c7;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --border: #cbd5e1;
    --text: #0f172a;
    --text-muted: #475569;
    --focus-ring: #0284c7;
    --font-scale: 1.25;
}

body.fs-small {
    --font-scale: 1;
}

body.fs-normal {
    --font-scale: 1.25;
}

body.fs-large {
    --font-scale: 1.5;
}

* {
    box-sizing: border-box;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: #ffffff;
    padding: 8px 16px;
    z-index: 1001;
    text-decoration: none;
    font-weight: bold;
    border-radius: 0 0 4px 0;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 12px;
    padding-bottom: calc(75px + env(safe-area-inset-bottom, 0px));
    display: flex;
    justify-content: center;
    transition: font-size 0.2s ease;
}

.app-container {
    width: 100%;
    max-width: 600px;
}

:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

header {
    padding: 12px 0px;
    background-color: #ffffff;
    border-bottom: 1px solid #e2e8f0;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 0;
}

.header-icon {
    height: 45px;
    width: 45px;
    flex-shrink: 0;
    border-radius: 10px;
    object-fit: contain;
}

.header-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.header-text h1 {
    margin: 0;
    font-size: calc(1.25rem * var(--font-scale));
    line-height: 1.2;
    color: #0f172a;
}

.status-bar {
    margin-top: 2px;
    font-size: calc(0.82rem * var(--font-scale));
    color: #64748b;
}

.controls-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    background: var(--card-bg);
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.control-label {
    font-size: calc(0.8rem * var(--font-scale));
    color: var(--text-muted);
    font-weight: 700;
}

.opt-btn {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    padding: 0 10px;
    height: 32px;
    font-size: calc(0.8rem * var(--font-scale));
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.opt-btn.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.fs-icon-sm {
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
}

.fs-icon-md {
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1;
}

.fs-icon-lg {
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;
}

.tabs-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 1000;
    margin-bottom: 0;
}

.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 4px 2px;
    margin-bottom: 10px;
    font-size: calc(0.72rem * var(--font-scale));
    font-weight: 700;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    opacity: 0.75;
}

.tab-btn.active {
    background: var(--primary-light);
    color: var(--primary);
    box-shadow: none;
    opacity: 1;
}

.tab-icon {
    width: 36px;
    height: 36px;
    object-fit: contain;
    display: block;
}

.tab-label {
    display: block;
    line-height: 1.1;
}

.subtabs-nav {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.subtab-btn {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--card-bg);
    padding: 8px;
    font-size: calc(0.8rem * var(--font-scale));
    font-weight: 700;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
}

.subtab-btn.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
}

.card-header {
    font-weight: 700;
    font-size: calc(1rem * var(--font-scale));
    padding-bottom: 8px;
    margin: 0 0 8px 0;
    border-bottom: 1px solid var(--border);
    color: var(--primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: calc(1rem * var(--font-scale));
    margin: 0;
    color: var(--primary);
}

.badge-minibus {
    background: var(--minibus-bg);
    color: var(--minibus);
    font-size: calc(0.7rem * var(--font-scale));
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
}

.badge-scheduled {
    background: var(--primary-light);
    color: var(--primary);
    font-size: calc(0.7rem * var(--font-scale));
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    border: 1px solid #bfdbfe;
}

.service-status-box {
    text-align: center;
    padding: 16px 12px;
    background: #f1f5f9;
    border-radius: 8px;
    border: 1px dashed var(--border);
    margin: 4px 0;
}

.service-status-title {
    font-size: calc(0.92rem * var(--font-scale));
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.service-status-sub {
    font-size: calc(1rem * var(--font-scale));
    font-weight: 800;
    color: var(--primary);
}

.schedule-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.schedule-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: calc(0.95rem * var(--font-scale));
    border-bottom: 1px dashed var(--border);
}

.schedule-item:last-child {
    border-bottom: none;
}

.schedule-item.next-bus {
    background-color: #f0fdf4;
    color: #15803d;
    font-weight: 700;
    border-left: 4px solid #16a34a;
    padding-left: 8px;
    border-radius: 4px;
}

.schedule-item.departed-bus {
    background-color: #fffbe3;
    color: #854d0e;
    font-weight: 700;
    border-left: 4px solid #eab308;
    padding-left: 8px;
    border-radius: 4px;
}

.grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.timetable-column-title {
    font-weight: 700;
    font-size: calc(0.9rem * var(--font-scale));
    text-align: center;
    padding: 6px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 6px;
    margin: 0 0 8px 0;
}

.time-slot-list {
    max-height: 420px;
    overflow-y: auto;
    font-size: calc(0.85rem * var(--font-scale));
    text-align: center;
    list-style: none;
    padding: 0;
    margin: 0;
}

.time-slot-item {
    padding: 6px 0;
    border-bottom: 1px dotted var(--border);
}

.time-slot-item.upcoming-highlight {
    background-color: #dcfce7;
    color: #15803d;
    font-weight: 800;
    font-size: 1.18em;
    border: 1px solid #86efac;
}

.passed {
    color: #64748b;
    text-decoration: line-through;
}

.sortable-header {
    display: flex;
    justify-content: space-between;
    user-select: none;
}

.sort-header-col.clickable {
    cursor: pointer;
    font-weight: 700;
    color: var(--primary);
}

.bus-card-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(4px * var(--font-scale) * var(--font-scale)) 0;
}

.bus-card-item.is-pinned {
    background-color: #fef3c7;
    border-left: 3px solid #d97706;
    padding-left: 6px;
    border-radius: 4px;
}

.bus-route-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    padding-right: 8px;
}

.bus-route-info>* {
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

/* Default unpinned icon styling: rotated -30deg with a lighter color */
.pin-btn {
    background: transparent;
    border: none;
    padding: 4px;
    margin-right: 2px;
    cursor: pointer;
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
    transform: rotate(-30deg);
}

.pin-btn:hover {
    color: var(--primary);
}

/* Pinned icon styling: pointing straight down with standard pin color */
.pin-btn.pinned {
    color: #d97706;
    transform: rotate(0deg);
}

.bus-route-badge {
    background: var(--primary);
    color: #ffffff;
    padding: 6px 8px;
    border-radius: 4px;
    font-weight: 800;
    font-size: calc(0.95rem * var(--font-scale));
}

.bus-route-badge.ctb {
    background: #b91c1c;
}

.bus-dest {
    display: inline-flex;
    align-items: baseline;
}

.bus-dest-prefix {
    font-size: 0.78em;
    font-weight: 400;
    color: var(--text-muted);
    margin-right: 2px;
}

.bus-dest-name {
    font-size: 1.08em;
    font-weight: 700;
    color: var(--text);
}

.bus-eta-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
    gap: 1px;
    max-width: 35%;
    flex-shrink: 0;
}

.bus-eta-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 4px;
}

.bus-eta-row.main-eta {
    font-size: calc(0.98rem * var(--font-scale));
    font-weight: 800;
    color: var(--accent);
    line-height: 1.2;
}

.bus-eta-row.sub-eta {
    font-size: calc(0.78rem * var(--font-scale));
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.15;
}

.eta-unit {
    font-size: calc(0.6rem * var(--font-scale));
    font-weight: 600;
    margin-left: 2px;
}

.bus-rmk-tag {
    display: inline-block;
    font-size: 0.7em;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 4px;
    margin-right: 4px;
    line-height: 1.2;
    white-space: normal;
    word-break: break-word;
    text-align: left;
}

.bus-rmk-tag.main {
    background: #e2e8f0;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.bus-rmk-tag.sub {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.hidden {
    display: none !important;
}