/* ============ 字体定义 ============ */
@font-face {
    font-family: 'ayfont';
    src: url('font/ayfont.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'ukijkufi';
    src: url('font/ukijkufi.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'ukijruqi';
    src: url('font/ukijruqi.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

* {
    font-family: 'ayfont', 'Inter', -apple-system, "PingFang SC", "Microsoft YaHei", 'Noto Naskh Arabic', 'Uighur', 'Microsoft Uighur', sans-serif;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-page: #f5f6fa;
    --bg-card: #ffffff;
    --bg-inner: #f2f3f7;
    --border-default: #ebedf0;
    --text-primary: #1a1a1a;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --accent: #6366f1;
    --accent-soft: #eef0ff;
    --accent-hover: #4f46e5;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(99, 102, 241, 0.08);
    --shadow-lg: 0 12px 32px rgba(99, 102, 241, 0.12);
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --font-ug: 'ayfont';
}

[data-theme="dark"] {
    --bg-page: #0a0a0f;
    --bg-card: #141419;
    --bg-inner: #1c1c22;
    --border-default: #26262e;
    --text-primary: #ededed;
    --text-secondary: #a1a1a1;
    --text-muted: #6b6b6b;
    --accent: #7c85f0;
    --accent-soft: #2a2d4a;
    --accent-hover: #9099ff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
    --success-soft: #0d2818;
    --danger-soft: #2a1515;
}

body {
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    padding-bottom: 40px;
    font-size: 14px;
    transition: background .25s ease, color .25s ease;
    background-image:
        radial-gradient(circle at 0% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 100% 0%, rgba(236, 72, 153, 0.06) 0%, transparent 40%);
    background-attachment: fixed;
}

/* ============ 维语字体（关键） ============ */
body.uighur,
body.uighur *,
body.uighur *::before,
body.uighur *::after {
    font-family: var(--font-ug, 'ayfont'), 'Noto Naskh Arabic', 'Uighur', 'Microsoft Uighur', 'Segoe UI', 'Inter', sans-serif !important;
}

.topbar {
    padding: 20px 20px 8px;
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar-greeting {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.topbar-hello {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.topbar-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bg-card);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s ease;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-inner);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.icon-btn:active { transform: scale(0.95); }

.icon-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lang-btn {
    width: auto;
    min-width: 42px;
    padding: 0 14px;
    height: 42px;
    border-radius: 21px;
    background: var(--bg-card);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s ease;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    flex-shrink: 0;
    white-space: nowrap;
}

.lang-btn:hover {
    background: var(--bg-inner);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.lang-btn:active { transform: scale(0.95); }

.text-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    padding: 7px 14px;
    border-radius: var(--radius-md);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s ease;
    font-family: inherit;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 5px;
}

.text-btn:hover {
    background: var(--bg-inner);
    color: var(--text-primary);
}

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

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px 20px 40px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    transition: all .2s ease;
}

.card:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.08), var(--shadow-md);
}

.field-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    font-family: inherit;
    padding: 4px 0;
    word-break: break-all;
    resize: none;
    min-height: 60px;
}

.field-input::placeholder { color: var(--text-muted); }

body.uighur .field-input {
    direction: rtl;
    text-align: right;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    width: 100%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    color: #fff;
    padding: 15px 24px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all .2s ease;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
    margin-bottom: 20px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 22px rgba(99, 102, 241, 0.45);
}

.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.tool-card {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 18px 16px 16px;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: all .25s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-default);
    overflow: hidden;
}

.tool-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--card-color, var(--accent));
    opacity: 0;
    transition: opacity .25s ease;
}

.tool-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: transparent;
}

.tool-card:hover::before { opacity: 1; }
.tool-card:active { transform: translateY(-2px) scale(0.99); }

.tool-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: transform .25s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.tool-card:hover .tool-icon {
    transform: scale(1.08) rotate(-4deg);
}

.tool-icon svg {
    width: 24px;
    height: 24px;
    stroke: #fff;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tool-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tool-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.35;
    letter-spacing: -0.01em;
}

.tool-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

body.uighur .tool-desc,
body.uighur .tool-name {
    direction: rtl;
    text-align: right;
}

.tool-arrow {
    position: absolute;
    top: 18px; right: 16px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--bg-inner);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all .25s ease;
}

body.uighur .tool-arrow {
    right: auto;
    left: 16px;
}

.tool-arrow svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tool-card:hover .tool-arrow {
    background: var(--card-color, var(--accent));
    color: #fff;
    transform: translateX(2px);
}

.tool-icon.c-blue { background: linear-gradient(135deg, #6366f1, #818cf8); }
.tool-icon.c-purple { background: linear-gradient(135deg, #8b5cf6, #a78bfa); }
.tool-icon.c-pink { background: linear-gradient(135deg, #ec4899, #f472b6); }
.tool-icon.c-green { background: linear-gradient(135deg, #10b981, #34d399); }
.tool-icon.c-orange { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.tool-icon.c-cyan { background: linear-gradient(135deg, #06b6d4, #22d3ee); }
.tool-icon.c-red { background: linear-gradient(135deg, #ef4444, #f87171); }
.tool-icon.c-indigo { background: linear-gradient(135deg, #4f46e5, #6366f1); }

.tool-card[data-color="blue"] { --card-color: #6366f1; }
.tool-card[data-color="purple"] { --card-color: #8b5cf6; }
.tool-card[data-color="pink"] { --card-color: #ec4899; }
.tool-card[data-color="green"] { --card-color: #10b981; }
.tool-card[data-color="orange"] { --card-color: #f59e0b; }
.tool-card[data-color="cyan"] { --card-color: #06b6d4; }
.tool-card[data-color="red"] { --card-color: #ef4444; }
.tool-card[data-color="indigo"] { --card-color: #4f46e5; }

.state-container {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
    display: none;
}

.state-container.show { display: block; }

.state-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.state-icon svg {
    width: 34px;
    height: 34px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.state-icon.error {
    background: var(--danger-soft);
    color: var(--danger);
}

.state-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.state-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.7;
    max-width: 400px;
    margin: 0 auto;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-default);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.spinner-small {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: var(--bg-page);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

@media (max-width: 400px) {
    .tools-grid { gap: 10px; }
    .tool-card { padding: 14px 12px 12px; }
    .tool-icon { width: 42px; height: 42px; border-radius: 12px; }
    .tool-icon svg { width: 20px; height: 20px; }
    .tool-name { font-size: 14px; }
    .tool-desc { font-size: 11px; }
    .topbar-title { font-size: 20px; }
}

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

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

.back-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bg-card);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s ease;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
    flex-shrink: 0;
    text-decoration: none;
}

.back-btn:hover {
    background: var(--bg-inner);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.back-btn:active { transform: scale(0.95); }

.back-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.topbar-full {
    padding: 20px 20px 8px;
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-full .topbar-greeting {
    flex: 1;
    min-width: 0;
}

.clear-cache-btn {
    width: 100%;
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 14px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    margin-top: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s ease;
}
.clear-cache-btn:hover { background: var(--danger-soft); }
.clear-cache-btn:active { transform: scale(0.98); }

/* ============ 底部导航 ============ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-card);
    border-top: 1px solid var(--border-default);
    display: flex;
    z-index: 100;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .bottom-nav {
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.3);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: color .15s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    padding: 6px 0 4px;
}

.bottom-nav-item:active { opacity: 0.7; }

.bottom-nav-item.active {
    color: var(--accent);
    font-weight: 600;
}

.bottom-nav-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    display: block;
    transition: transform .15s ease;
}

.bottom-nav-item:active .bottom-nav-icon {
    transform: scale(0.92);
}

body.has-bottom-nav {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
}

body.has-bottom-nav .container {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
}