/* === Reset & Base === */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f2f2f7;
    color: #1d1d1f;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
}

/* === Layout === */
.container { max-width: 500px; margin: 0 auto; padding: 0 16px; }
.home-container { padding-top: 60px; padding-bottom: 40px; }

.app-layout { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.app-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
    background: #fff; border-bottom: 1px solid #e5e5ea;
    position: sticky; top: 0; z-index: 100;
}
.app-header h1 { font-size: 20px; font-weight: 700; }
.header-left { flex: 1; min-width: 0; }
.header-right { display: flex; gap: 8px; align-items: center; }
.app-main {
    flex: 1; padding: 16px;
    max-width: 500px; width: 100%; margin: 0 auto;
}

/* === Hero === */
.hero { text-align: center; margin-bottom: 32px; }
.hero-icon { font-size: 64px; margin-bottom: 12px; }
.hero h1 { font-size: 28px; font-weight: 800; margin-bottom: 8px; }
.subtitle { color: #86868b; font-size: 17px; }

/* === Card === */
.card {
    background: #fff; border-radius: 16px; padding: 20px;
    margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.card h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }

/* === Buttons === */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 12px 24px; border: none; border-radius: 12px;
    font-size: 16px; font-weight: 600; cursor: pointer;
    min-height: 48px; transition: opacity 0.2s;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: #007aff; color: #fff; }
.btn-lg { padding: 16px 32px; font-size: 17px; min-height: 54px; }
.btn-block { width: 100%; }
.btn-icon {
    background: none; border: none; font-size: 24px; cursor: pointer;
    padding: 8px; min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
    color: inherit;
}

/* === Form === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 15px; }
.form-group input, .form-group select {
    width: 100%; padding: 14px 16px; border: 1px solid #d2d2d7;
    border-radius: 12px; font-size: 17px; background: #fff;
    -webkit-appearance: none;
}
.form-group input:focus { outline: none; border-color: #007aff; box-shadow: 0 0 0 3px rgba(0,122,255,0.15); }

/* === Recent === */
.recent-item-row { display: flex; align-items: center; border-bottom: 1px solid #f5f5f7; }
.recent-item-row:last-child { border-bottom: none; }
.recent-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 0; text-decoration: none; color: #1d1d1f;
    min-height: 48px; flex: 1;
}
.recent-name { font-weight: 500; font-size: 16px; }
.recent-arrow { color: #86868b; font-size: 18px; }

/* === Room Page === */
.room-body {
    overflow: hidden; height: 100vh; height: 100dvh;
    display: flex; flex-direction: column;
    padding-bottom: 0;
    background: var(--page-bg, #f2f2f7);
    color: var(--card-text, #1d1d1f);
}
.room-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
    background: var(--header-bg, #fff); border-bottom: 1px solid var(--header-border, #e5e5ea);
    color: var(--header-text, #1d1d1f);
    z-index: 100; flex-shrink: 0;
}
.room-header h1 { font-size: 20px; font-weight: 700; color: var(--header-text, #1d1d1f); }
.speed-select {
    padding: 6px 10px; border-radius: 8px; font-size: 13px; font-weight: 600;
    border: 1px solid var(--header-border, #e5e5ea);
    background: var(--page-bg, #f2f2f7); color: var(--header-text, #1d1d1f);
    -webkit-appearance: none; appearance: none;
    min-height: 36px;
}
.room-scroll {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    background: var(--page-bg, #f2f2f7);
}
.radar-wrap {
    width: 100%; aspect-ratio: 1 / 1; max-height: 70vh;
    position: relative; background: #f8f8fa;
}
.radar-wrap canvas { display: block; }
.theme-label {
    position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.6); color: #fff; padding: 6px 14px;
    border-radius: 20px; font-size: 13px; font-weight: 600;
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.theme-label.show { opacity: 1; }
.sweep-speed {
    position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 6px; background: rgba(0,0,0,0.5); padding: 4px;
    border-radius: 10px;
}
.speed-btn {
    background: transparent; border: none; color: rgba(255,255,255,0.5);
    font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 7px;
    cursor: pointer; min-width: 40px;
}
.speed-btn.active {
    background: rgba(0,255,65,0.25); color: #00ff41;
}
.status-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px; padding-bottom: calc(10px + env(safe-area-inset-bottom));
    background: var(--status-bg, #fff); border-top: 1px solid var(--status-border, #e5e5ea);
    font-size: 14px; font-weight: 500; color: var(--status-text, #86868b);
    flex-shrink: 0;
}

/* === Distance List === */
.dist-list {
    padding: 8px 16px; padding-bottom: 8px;
}
.dist-row {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px; margin-bottom: 8px;
    background: var(--card-bg, #fff); border-radius: 14px;
    box-shadow: 0 1px 3px var(--card-border, rgba(0,0,0,0.06));
}
.dist-row.waiting { opacity: 0.5; }
.dist-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.dist-info { flex: 1; min-width: 0; }
.dist-name { font-size: 16px; font-weight: 600; color: var(--card-text, #1d1d1f); }
.dist-dir { font-size: 13px; color: var(--card-sub, #86868b); margin-top: 2px; }
.dist-val {
    font-size: 20px; font-weight: 800; flex-shrink: 0; text-align: right;
}
.sort-toggle {
    display: flex; gap: 4px; padding: 0 0 8px; justify-content: center;
}
.sort-btn {
    padding: 5px 14px; border: 1px solid var(--header-border, #e5e5ea);
    border-radius: 8px; font-size: 12px; font-weight: 600;
    background: var(--card-bg, #fff); color: var(--card-sub, #86868b);
    cursor: pointer;
}
.sort-btn.active {
    background: var(--accent, #007aff); color: #fff; border-color: var(--accent, #007aff);
}
.drag-handle {
    color: var(--card-sub, #c7c7cc); font-size: 16px; cursor: grab;
    padding: 0 4px; flex-shrink: 0; user-select: none;
    display: flex; align-items: center;
}
.dist-row.dragging { opacity: 0.4; }
.dist-row.drag-over { border: 2px dashed var(--accent, #007aff); }
.drag-clone {
    position: fixed; z-index: 300; opacity: 0.85; pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2); border-radius: 14px;
}
.dist-empty {
    text-align: center; padding: 30px 16px; color: var(--card-sub, #86868b);
    font-size: 15px; font-weight: 500;
}
.dist-waiting {
    padding: 8px 16px; background: #fff7ed; border-top: 1px solid #fed7aa;
    font-size: 13px; color: #9a3412; text-align: center;
}

/* === Empty State === */
.empty-state { text-align: center; padding: 60px 20px; color: #86868b; }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 17px; font-weight: 600; }
.text-muted { color: #86868b; font-size: 14px; }

/* === Modal === */
.modal {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; visibility: hidden; transition: all 0.3s;
}
.modal.active { opacity: 1; visibility: visible; }
.modal-overlay {
    position: absolute; inset: 0; background: rgba(0,0,0,0.4);
}
.modal-content {
    position: relative; background: #fff; border-radius: 20px;
    padding: 28px; margin: 20px; max-width: 400px; width: 100%;
    transform: scale(0.9); transition: transform 0.3s;
}
.modal.active .modal-content { transform: scale(1); }
.modal-content h3 { font-size: 20px; font-weight: 700; margin-bottom: 12px; }

/* === Map Theme === */
.map-dot { background: none !important; border: none !important; }
.map-tooltip {
    font-size: 12px !important; font-weight: 600 !important;
    padding: 2px 8px !important; border-radius: 8px !important;
    border: none !important; box-shadow: 0 1px 4px rgba(0,0,0,0.2) !important;
}
#mapContainer .leaflet-control-attribution { font-size: 10px; }

.share-link-box { display: flex; gap: 8px; margin: 12px 0; }
.share-link-box input {
    flex: 1; padding: 12px; border: 1px solid #d2d2d7;
    border-radius: 10px; font-size: 14px; background: #f5f5f7;
    min-width: 0;
}
