:root {
    --primary: #1a2236;
    --accent: #3498db;
    --bg: #f4f7f6;
    --white: #ffffff;
}

/* ─── Base ─────────────────────────────────────────────── */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    padding-top: env(safe-area-inset-top, 0px);
}

/* ─── App Grid / Menu View ──────────────────────────────── */
.container {
    padding: 20px 16px;
    max-width: 640px;
    margin: 0 auto;
    overflow-y: auto;
    height: 90vh;
}

header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
header h1 { font-size: 20px; margin: 0 0 2px; cursor: default; color: #111; }
header p  { color: #888; margin: 0; font-size: 12px; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

/* ─── Cards ─────────────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    border: 1.5px solid #f0f0f0;
}
.card:hover  { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.13); }
.card:active { transform: scale(0.97); }

.card-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}
.card-body {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.card-title { font-size: 13px; font-weight: 700; color: #111; margin: 0; }
.card-sub   { font-size: 11px; color: #999; margin: 0; }
.card-accent { height: 3px; width: 100%; }

/* Card Groups */
.card-group { margin-bottom: 24px; }
.card-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0 2px 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid;
    opacity: 0.75;
}
.card-group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
    padding-top: 10px;
}

/* Visual Category Colors */
.mapping      { border-color: #27ae60; }
.congregation { border-color: #9b59b6; }
.ministry     { border-color: #e67e22; }

/* ─── Generic Button ─────────────────────────────────────── */
.btn {
    cursor: pointer;
    border: none;
    background: var(--accent);
    color: white;
    padding: 10px;
    border-radius: 6px;
    font-weight: bold;
    margin-top: auto;
}

/* ─── Modal ──────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    backdrop-filter: blur(4px);
    padding-top: max(20px, env(safe-area-inset-top, 20px));
}

.modal-content {
    background: #fff;
    border-radius: 16px;
    padding: 32px 28px 24px;
    width: min(420px, 92vw);
    box-shadow: 0 24px 60px rgba(0,0,0,0.25);
    font-family: system-ui, sans-serif;
    margin-top: env(safe-area-inset-top, 0px);
    position: relative;
}
.modal-content h2 { margin: 0 0 6px; font-size: 22px; color: #111; }

.modal-subtitle {
    font-size: 13px;
    color: #666;
    margin: 0 0 24px;
    line-height: 1.5;
}

/* ─── PIN Input ──────────────────────────────────────────── */
.code-hint {
    display: flex;
    justify-content: center;
    font-size: 11px;
    color: #999;
    margin-bottom: 4px;
    font-family: monospace;
    letter-spacing: 1px;
    gap: 4px;
}
.code-hint .h-skill { color: #0078a8; font-weight: bold; }
.code-hint .h-cong  { color: #2e7d32; font-weight: bold; }

#code-input {
    width: 100%;
    box-sizing: border-box;
    padding: 16px 14px;
    font-size: 26px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    letter-spacing: 4px;
    text-align: center;
    border: 2px solid #ddd;
    border-radius: 10px;
    outline: none;
    color: #111;
    transition: border-color 0.2s;
    margin-bottom: 8px;
}
#code-input:focus { border-color: #0078a8; }

#code-error {
    font-size: 12px;
    color: #c62828;
    text-align: center;
    min-height: 16px;
    margin-bottom: 16px;
    display: none;
}

/* ─── Modal Buttons ──────────────────────────────────────── */
.modal-btns { display: flex; gap: 10px; }

.btn-confirm {
    flex: 1;
    padding: 13px;
    background: #0078a8;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-confirm:hover { background: #005f8a; }

.btn-cancel {
    padding: 13px 18px;
    background: #f0f0f0;
    color: #444;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    cursor: pointer;
}
.btn-cancel:hover { background: #e0e0e0; }

.btn-help {
    background: #3498db;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
}

.btn-back {
    width: 100%;
    padding: 12px;
    background: #f0f0f0;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    color: #333;
}
.btn-back:hover { background: #e0e0e0; }

/* ─── Guide Panel ────────────────────────────────────────── */
#guide-panel { display: none; }
#guide-panel h3 { margin: 0 0 12px; font-size: 17px; color: #111; }
#guide-panel p  { font-size: 13px; color: #444; margin: 0 0 14px; }

.guide-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 8px 0 14px;
}
.guide-table th {
    background: #f5f5f5;
    padding: 6px 10px;
    text-align: left;
    border-bottom: 2px solid #ddd;
}
.guide-table td { padding: 6px 10px; border-bottom: 1px solid #eee; }
.guide-table tr:last-child td { border-bottom: none; }

/* ─── Iframe Shell ───────────────────────────────────────── */
#app-shell {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    z-index: 100;
}
#app-shell[style*="display: none"] {
    pointer-events: none !important;
    visibility: hidden;
}

/* ─── Floating Action Buttons ────────────────────────────── */
.fab-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 99999 !important;
    width: min-content;
    pointer-events: none;
}
.fab {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}
.home-btn  { background: #27ae60; font-size: 1.5rem; }
.reset-btn { background: var(--primary); font-size: 0.7rem; }

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top, 0px);
    background: var(--bg);
    z-index: 99999;
}