/* احتياجاتي - تصميم وتنسيق */
:root {
    --bg: #05050b;
    --surface: #0d1430;
    --surface-2: #131c3d;
    --border: #2a3a66;
    --text: #ffffff;
    --text-dim: #b7c3e0;
    --accent: #00f3ff;
    --accent-2: #ff0055;
    --green: #7cff6b;
    --yellow: #ffe600;
    --danger: #ff3b30;
    --radius: 22px;
    --tile-emoji: 52px;
    --tile-name: 22px;
}

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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== الشريط العلوي ===== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: linear-gradient(180deg, #0b3d91, #0a2a63);
    border-bottom: 3px solid var(--accent);
    flex-shrink: 0;
}

.app-title {
    font-size: 26px;
    font-weight: 900;
    margin: 0;
    color: var(--text);
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.app-title-sub {
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
}

.top-actions {
    display: flex;
    gap: 10px;
}

.icon-btn {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 26px;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

.icon-btn:active { transform: scale(0.9); background: var(--surface-2); }
.icon-btn.on { background: var(--accent); border-color: var(--accent); }

/* ===== الفئات ===== */
.tabs {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
    flex-shrink: 0;
    padding: 10px 18px;
    font-family: inherit;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-dim);
    background: var(--surface-2);
    border: 2px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn:active { transform: scale(0.94); }

.tab-btn.active {
    color: #00122a;
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 900;
}

/* ===== الشبكة ===== */
.grid {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    align-content: start;
}

@media (min-width: 520px) {
    .grid { grid-template-columns: repeat(4, 1fr); }
}

body.big-mode .grid { grid-template-columns: repeat(2, 1fr); }
body.big-mode .grid { --tile-emoji: 72px; --tile-name: 28px; }

@supports not (gap: 12px) {
    .grid { gap: 0; }
    .tile, .tile-add { margin: 6px; }
}

.tile {
    position: relative;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 3px solid var(--border);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    padding: 8px;
    transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s;
}

.tile:active {
    transform: scale(0.93);
    box-shadow: 0 0 26px var(--tile-accent, var(--accent));
}

.tile-emoji {
    font-size: var(--tile-emoji);
    line-height: 1;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.6));
}

.tile-name {
    font-size: var(--tile-name);
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
}

.tile-sound {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 15px;
    opacity: 0.85;
}

.tile-edit-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--yellow);
    color: #111;
    font-size: 15px;
    border: 2px solid #111;
}

.tile-del-badge {
    position: absolute;
    bottom: 8px;
    left: 8px;
    width: 30px;
    height: 30px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    font-size: 17px;
    font-weight: 900;
    border: 2px solid #fff;
}

body.editing .tile-edit-badge,
body.editing .tile-del-badge { display: flex; }

body.editing .tile { border-style: dashed; border-color: var(--yellow); }

/* زرار الإضافة */
.tile-add {
    min-height: 150px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    background: rgba(0, 243, 255, 0.06);
    border: 3px dashed var(--accent);
    color: var(--accent);
    font-size: 46px;
    font-family: inherit;
    cursor: pointer;
}

body.editing .tile-add { display: flex; }

.tile-add:active { transform: scale(0.93); }

/* ===== زر الاستغاثة ===== */
.bottom-bar {
    flex-shrink: 0;
    padding: 10px 14px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.sos-btn {
    width: 100%;
    padding: 16px;
    font-family: inherit;
    font-size: 26px;
    font-weight: 900;
    color: #fff;
    background: linear-gradient(90deg, #d50000, #ff3b30);
    border: 3px solid #ffd7d7;
    border-radius: 18px;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(255, 59, 48, 0.5);
    transition: transform 0.08s;
}

.sos-btn:active { transform: scale(0.97); }

/* ===== شاشة الاستغاثة ===== */
.sos-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #b20000;
    animation: sos-flash 0.8s infinite;
}

@keyframes sos-flash {
    0%, 100% { background: #b20000; }
    50% { background: #ff2d00; }
}

.sos-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.sos-icon { font-size: 120px; animation: sos-pulse 0.8s infinite; }

@keyframes sos-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.sos-text {
    font-size: 58px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.sos-stop-btn {
    padding: 18px 60px;
    font-size: 30px;
    border-radius: 18px;
    border: none;
    background: #fff;
    color: #b20000;
    font-weight: 900;
    font-family: inherit;
    cursor: pointer;
}

/* ===== الأزرار العامة ===== */
.btn {
    font-family: inherit;
    font-size: 19px;
    font-weight: 700;
    padding: 13px 20px;
    border-radius: 14px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.08s;
}

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

.primary-btn { background: var(--accent); color: #00122a; }
.secondary-btn { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.danger-btn { background: var(--danger); color: #fff; }

/* ===== النوافذ ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    padding: 14px;
}

.modal-box {
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    overflow-y: auto;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-box h2 {
    margin: 0 0 6px;
    font-size: 26px;
    text-align: center;
    color: var(--accent);
}

.field-label {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-dim);
}

.field-input, .field-select {
    width: 100%;
    padding: 12px 14px;
    font-size: 20px;
    font-family: inherit;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}

.field-input:focus, .field-select:focus { outline: none; border-color: var(--accent); }

.voice-status {
    font-size: 16px;
    font-weight: 700;
    padding: 10px 14px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--surface-2);
    color: var(--text-dim);
    line-height: 1.6;
}

.voice-status.ok { color: var(--green); border-color: var(--green); }
.voice-status.warn { color: var(--yellow); border-color: var(--yellow); }
.voice-status.err { color: #ff9d9d; border-color: var(--danger); }

.voice-hint {
    font-size: 14px;
    color: var(--text-dim);
    margin: -2px 0 4px;
    line-height: 1.5;
}

.emoji-picker {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
    background: var(--surface-2);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 8px;
}

.emoji-opt {
    font-size: 28px;
    padding: 6px 0;
    border-radius: 10px;
    background: transparent;
    border: 2px solid transparent;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.08s;
}

.emoji-opt:active { transform: scale(0.9); }

.emoji-opt.selected {
    background: var(--accent);
    border-color: #fff;
    transform: scale(1.05);
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 6px;
    justify-content: center;
}

.modal-actions .btn { flex: 1; min-width: 100px; }

/* ===== مفتاح تبديل ===== */
.switch {
    position: relative;
    display: inline-block;
    width: 64px;
    height: 34px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--surface-2);
    border: 2px solid var(--border);
    border-radius: 34px;
    transition: 0.2s;
}

.switch-slider::before {
    content: "";
    position: absolute;
    right: 3px;
    top: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: 0.2s;
}

.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(-28px); background: #00122a; }

/* ===== مساعدة عامة ===== */
.hidden { display: none !important; }

/* ===== فقاعة الكلام ===== */
.speech-bubble {
    position: fixed;
    bottom: 130px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 88%;
    background: var(--surface);
    border: 3px solid var(--accent);
    border-radius: 22px;
    padding: 16px 26px;
    font-size: 34px;
    font-weight: 900;
    text-align: center;
    color: var(--text);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    z-index: 30;
    pointer-events: none;
    animation: bubble-pop 0.25s ease-out;
    white-space: nowrap;
}

@keyframes bubble-pop {
    0% { transform: translateX(-50%) scale(0.6); opacity: 0; }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}
