:root {
    --hoc-green: #0B4628;
    --hoc-gold: #C59217;
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --btn-red: #ef4444;
    --btn-yellow: #f59e0b;
    --btn-green: #22c55e;
    --text-color: #333;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.unofficial-overlay {
    position: absolute;
    bottom: 0px;
    width: 100%;
    background: rgba(0,0,0,0.6);
    color: white;
    font-size: 0.75rem;
    padding: 5px;
    text-align: center;
    display: none;
    backdrop-filter: blur(2px);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    pointer-events: none;
    z-index: 5;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    color: var(--text-color);
    -webkit-tap-highlight-color: transparent;
}

/* --- HEADER --- */
header {
    box-sizing: border-box;
    background-color: var(--hoc-green);
    width: 100%;
    padding-top: max(15px, env(safe-area-inset-top));
    padding-bottom: 15px;
    padding-left: 20px;
    padding-right: 20px;
    color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    flex-shrink: 0;
}

h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.mode-btn {
    background: var(--hoc-gold);
    color: #1a1200;
}

.mode-btn:hover {
    background: #d4a01c;
}

/* --- MAIN APP AREA --- */
main {
    min-height: 0;
    flex: 1;
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    box-sizing: border-box;
    position: relative;
    overflow-y: auto;
}

.main-area {
    min-height: 0;
    overflow-y: auto;
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: safe center;
    position: relative;
}

/* --- FLASHCARD --- */
.card-container {
    position: relative;
    flex-shrink: 0;
    width: 100%;
    max-width: 340px;
    height: 440px;
    perspective: 1000px;
    cursor: pointer;
}

.card {
    width: 100%;
    height: 100%;
    position: relative;
    box-shadow: var(--shadow);
    border-radius: 16px;
    overflow: hidden;
    background: var(--card-bg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.card-front {
    top: 0;
    left: 0;
    justify-content: flex-start;
    align-items: center;
    background: #e2e8f0;
}

.card-back {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-height: 50%;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 5px solid var(--hoc-green);
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px 18px 14px;
    text-align: center;
    transform: translateY(105%);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 10;
}

.card.flipped .card-back {
    transform: translateY(0);
}

.mp-img-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.mp-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.card.flipped .mp-img {
    height: 50%;
    align-self: flex-start;
    object-fit: contain;
}

/* Card Back Content */
.back-header {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
}

.mp-honorific {
    font-size: 0.85rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    font-weight: 600;
}

.mp-name {
    font-size: 1.4rem;
    font-weight: 700;
    color: #1a202c;
    margin: 0 0 4px 0;
    line-height: 1.2;
}

.mp-party {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    padding: 4px 12px;
    border-radius: 12px;
    background: #f1f5f9;
    display: inline-block;
}

.back-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.info-item {
    font-size: 0.95rem;
    color: #4a5568;
}

.info-item strong {
    color: #2d3748;
}

.mp-roles {
    font-size: 0.85rem;
    background: #fffbeb;
    border: 1px solid #fef3c7;
    color: #b45309;
    padding: 8px;
    border-radius: 8px;
    margin-top: 5px;
    font-weight: 500;
}

.back-footer {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid #e2e8f0;
}

.action-link {
    color: var(--hoc-green);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.action-link:hover {
    text-decoration: underline;
}

.audio-btn {
    background: #f1f5f9;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #4a5568;
    transition: background 0.2s ease;
}

.audio-btn:hover {
    background: #e2e8f0;
    color: var(--hoc-green);
}

.audio-btn.playing {
    background: #dcfce7;
    color: #15803d;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

/* --- MASTERY & NAVIGATION --- */
.controls-area {
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom);
    width: 100%;
    max-width: 340px;
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mastery-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.mastery-btn {
    flex: 1;
    padding: 10px 4px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s ease, filter 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mastery-btn:active {
    transform: scale(0.96);
}

.btn-miss {
    background-color: #C62828;
    color: #ffffff;
    border: 1px solid #AD2020;
}
.btn-good {
    background-color: #F2C744;
    color: #332600;
    border: 1px solid var(--hoc-gold);
}
.btn-easy {
    background-color: var(--hoc-green);
    color: #ffffff;
    border: 1px solid #08361F;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    font-size: 1.85rem;
    font-weight: 700;
    line-height: 1;
}

.nav-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.nav-btn {
    background: white;
    border: 1px solid #cbd5e1;
    padding: 8px 24px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1.15rem;
    min-width: 65px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    color: #334155;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}

.nav-btn.primary {
    background: var(--hoc-green);
    color: white;
    border: none;
}

.nav-btn.primary:hover {
    background: #08351e;
}

/* --- QUIZ MODE --- */
.quiz-container {
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.quiz-img-wrapper {
    width: 200px;
    height: 250px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    background: #e2e8f0;
}

.quiz-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
}

.quiz-options {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quiz-btn {
    width: 100%;
    padding: 12px 15px;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.quiz-btn:hover:not(:disabled) {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.quiz-btn.correct {
    background: #dcfce7 !important;
    border-color: #22c55e !important;
    color: #15803d !important;
}

.quiz-btn.wrong {
    background: #fee2e2 !important;
    border-color: #ef4444 !important;
    color: #b91c1c !important;
}

/* --- MODALS --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: white;
    width: 100%;
    max-width: 420px;
    max-height: 85vh;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.open .modal-card {
    transform: translateY(0);
}

.modal-header {
    padding: 15px 20px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: #64748b;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Filter/Setting Inputs */
.setting-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
}

.setting-select, .search-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: white;
    font-size: 0.95rem;
    color: #1e293b;
    box-sizing: border-box;
}

.search-results {
    margin-top: 5px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
}

.search-result-item:hover {
    background: #f8fafc;
}

.search-result-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.search-result-info {
    display: flex;
    flex-direction: column;
}

.search-result-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
}

.search-result-meta {
    font-size: 0.75rem;
    color: #64748b;
}



/* Dashboard UI */
.dash-ring-wrap {
    display: flex;
    align-items: center;
    gap: 15px;
}

.dash-ring {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: conic-gradient(var(--hoc-green) calc(var(--pct) * 1%), #e2e8f0 0);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dash-ring-inner {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.dash-ring-inner b { font-size: 0.95rem; line-height: 1; }
.dash-ring-inner small { font-size: 0.65rem; color: #64748b; }

.dash-ring-caption {
    font-size: 0.85rem;
    color: #475569;
    line-height: 1.4;
}

.dash-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.dash-stat {
    background: #f8fafc;
    border-radius: 8px;
    padding: 8px;
    text-align: center;
    border-top: 3px solid var(--lvl);
}

.dash-stat .num { font-size: 1.1rem; font-weight: 700; color: #1e293b; }
.dash-stat .lbl { font-size: 0.7rem; color: #64748b; }

.dash-due {
    background: #f1f5f9;
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
}

.dash-due.none { color: #166534; background: #f0fdf4; }

.dash-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 5px;
}

.dash-party-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}

.dash-party-row .pname { width: 110px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-bar { flex: 1; height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
.dash-bar span { display: block; height: 100%; border-radius: 4px; }
.dash-party-row .pval { width: 45px; text-align: right; font-weight: 600; color: #64748b; font-size: 0.75rem; }

.dash-empty {
    text-align: center;
    padding: 20px;
    color: #64748b;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* --- CHAMBER SEATING MAP MODAL & VIEW --- */
.chamber-modal-card {
    max-width: 720px;
    width: 95vw;
}

.chamber-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-items: center;
}

.chamber-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    background: #f8fafc;
    padding: 8px 14px;
    border-radius: 20px;
    width: 100%;
    box-sizing: border-box;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.chamber-svg-wrapper {
    width: 100%;
    background: #0b4628;
    border-radius: 12px;
    padding: 15px;
    box-sizing: border-box;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.3);
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.chamber-svg {
    width: 100%;
    height: auto;
    display: block;
}

.seat-circle, .speaker-seat {
    cursor: pointer;
}

.seat-circle:hover, .seat-circle:focus,
.speaker-seat:hover rect, .speaker-seat:focus rect {
    stroke: #ffffff;
    stroke-width: 2.5px;
    outline: none;
}

.seat-circle.selected, .speaker-seat.selected rect {
    stroke: #c59217;
    stroke-width: 3.5px;
}

.chamber-tooltip {
    position: sticky;
    top: 0;
    z-index: 2;
    width: 100%;
    box-sizing: border-box;
    min-height: 64px;
    background: #f8fafc;
    border: 1px solid #dce5ed;
    color: #0f172a;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chamber-tooltip-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--hoc-gold);
}

.chamber-tooltip-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.chamber-tooltip-name {
    font-weight: 700;
    font-size: 0.9rem;
}

.chamber-tooltip-meta {
    font-size: 0.75rem;
    opacity: 0.8;
}

.chamber-open-card {
    flex: none;
    border: 0;
    border-radius: 8px;
    background: #0b4628;
    color: white;
    padding: 9px 12px;
    font-weight: 700;
    cursor: pointer;
}

@media (max-width: 600px) {
    .chamber-svg { min-width: 800px; }
    .chamber-tooltip { flex-wrap: wrap; }
    .chamber-open-card { margin-left: auto; }
}

/* PWA Toasts & Badges */
#precache-toast, #update-toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translate(-50%, 150%);
    width: min(420px, calc(100% - 32px));
    background: var(--hoc-green);
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    font-size: 0.85rem;
    z-index: 9999;
    opacity: 0;
    transition: transform 0.35s ease, opacity 0.35s ease;
    pointer-events: none;
}
#precache-toast.visible, #update-toast.visible {
    transform: translate(-50%, 0);
    opacity: 1;
    pointer-events: auto;
}
#precache-label { margin-bottom: 8px; font-weight: 600; }
#precache-track {
    height: 6px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
    overflow: hidden;
}
#precache-fill {
    height: 100%;
    width: 0%;
    background: var(--hoc-gold);
    border-radius: 3px;
    transition: width 0.3s ease;
}
#update-toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-weight: 600;
}
#update-btn {
    background: var(--hoc-gold);
    color: #1a1200;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
#install-btn {
    position: fixed;
    right: 16px;
    bottom: 20px;
    display: none;
    align-items: center;
    gap: 6px;
    background: var(--hoc-green);
    color: #fff;
    border: 1px solid var(--hoc-gold);
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: var(--shadow);
    cursor: pointer;
    z-index: 9998;
}
#install-btn.visible { display: inline-flex; }
#offline-badge {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 50%;
    transform: translate(-50%, -150%);
    margin-top: 8px;
    background: var(--btn-yellow);
    color: #3a2a00;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    box-shadow: var(--shadow);
    z-index: 10000;
    transition: transform 0.3s ease;
    pointer-events: none;
}
#offline-badge.visible { transform: translate(-50%, 0); }

/* Keep controls accessible on narrow phones and in landscape. */
@media (max-width: 420px) {
    header { padding-left: 10px; padding-right: 10px; gap: 6px; }
    h1 { font-size: 1.1rem; }
    .header-controls { gap: 5px; }
    .icon-btn { padding: 8px; font-size: 0.8rem; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
    .card-back, .mp-img { transition: none; }
}

/* A small photo-corner hint remains available while details are open. */
.reveal-hint {
    position: absolute;
    right: 6px;
    bottom: 6px;
    z-index: 20;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    color: var(--hoc-green);
    cursor: pointer;
}
.reveal-hint:hover, .reveal-hint:focus-visible {
    background: rgba(255, 255, 255, 0.8);
}
.reveal-hint:focus-visible { outline: 2px solid var(--hoc-green); }
.card.flipped + .reveal-hint { bottom: calc(50% + 6px); }
.card.flipped + .reveal-hint svg { transform: rotate(180deg); }

/* Hidden rhyme switch preserves the menu heading's appearance. */
.menu-title-toggle { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.menu-title-toggle:focus-visible { outline: 2px solid var(--hoc-gold); outline-offset: 4px; border-radius: 3px; }
.menu-title-toggle[aria-pressed="true"] { color: var(--hoc-green); }
