:root {
    --system-bg: #fbfbfd;
    --material-bg: rgba(255, 255, 255, 0.85);
    --material-border: rgba(0, 0, 0, 0.08);
    --text-main: #1d1d1f;
    --text-sub: #6e6e73;
    --accent: #0071e3;
    --danger: #ff3b30;
    --tag-bg: rgba(0, 0, 0, 0.04);
    --editor-shadow: rgba(0, 0, 0, 0.03);
    --select-dropdown-bg: #ffffff;
    --spring-easing: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

[data-theme="dark"] {
    --system-bg: #000000;
    --material-bg: rgba(28, 28, 30, 0.85);
    --material-border: rgba(255, 255, 255, 0.1);
    --text-main: #f5f5f7;
    --text-sub: #86868b;
    --accent: #0a84ff;
    --danger: #ff453a;
    --tag-bg: rgba(255, 255, 255, 0.08);
    --editor-shadow: rgba(0, 0, 0, 0.2);
    --select-dropdown-bg: #1c1c1e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--system-bg);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.canvas-bg {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;
    background: radial-gradient(circle at 50% 0%, var(--accent), transparent 70%);
    opacity: 0.1;
}

/* FIX: Absolute pin to top-right with explicit margins */
.top-nav {
    position: absolute; /* Using absolute to stay within document flow but pinned */
    top: 32px;
    right: 32px;
    margin: 0;
    padding: 0;
    z-index: 9999;
}

/* Ensure the button itself doesn't have floating issues */
#themeToggle {
    display: block;
    float: right;
}

.apple-shell { max-width: 850px; margin: 80px auto 40px; padding: 20px; }

.hero-section { text-align: center; margin-bottom: 40px; }
.app-icon { font-size: 3.5rem; display: block; margin-bottom: 8px; }
h1 { font-size: 2.4rem; font-weight: 800; letter-spacing: -0.02em; }
.hero-section p { color: var(--text-sub); font-size: 1.1rem; }

.glass {
    background: var(--material-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--material-border);
    border-radius: 28px;
}

.surface-content { padding: 32px 32px 10px 32px; }

.toolbar { display: flex; justify-content: space-between; gap: 15px; margin-bottom: 24px; }
.toolbar-group { display: flex; gap: 10px; }

.apple-select {
    background: var(--tag-bg);
    border: none;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px;
    padding-right: 38px;
}

.apple-select option {
    background-color: var(--select-dropdown-bg);
    color: var(--text-main);
}

.apple-input {
    background: var(--tag-bg);
    border: none;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
}

.apple-input.small { width: 60px; text-align: center; }

button {
    position: relative;
    overflow: hidden;
    transition: transform 0.2s var(--spring-easing), opacity 0.2s ease;
    cursor: pointer;
    border: none;
    user-select: none;
}

button:active { transform: scale(0.94); }

.apple-btn-primary { background: var(--accent); color: white; padding: 12px 24px; border-radius: 12px; font-weight: 600; }
.apple-btn-secondary { background: var(--tag-bg); color: var(--text-main); padding: 12px 24px; border-radius: 12px; font-weight: 600; }
.apple-btn-danger { background: rgba(255, 59, 48, 0.1); color: var(--danger); padding: 12px 24px; border-radius: 12px; font-weight: 600; }

.haptic-ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripple-animation 0.6s linear;
    background-color: rgba(255, 255, 255, 0.35);
    pointer-events: none;
}

@keyframes ripple-animation {
    to { transform: scale(4); opacity: 0; }
}

.apple-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.word-tag { background: var(--tag-bg); padding: 5px 12px; border-radius: 10px; font-size: 0.85rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.delete-tag-btn { background: transparent; color: var(--text-sub); font-weight: 800; }
.text-btn { background: none; color: var(--accent); font-weight: 700; padding: 4px 8px; border-radius: 6px; }

.separator { height: 1px; background: var(--material-border); margin-bottom: 20px; }

.apple-editor { 
    min-height: 250px; font-size: 1.2rem; outline: none; line-height: 1.6;
    padding: 20px; border-radius: 18px; background: var(--tag-bg);
    box-shadow: inset 0 2px 8px var(--editor-shadow);
}
.apple-editor:empty:before { content: attr(placeholder); color: var(--text-sub); opacity: 0.6; }

.info-bar {
    padding: 24px 32px;
    background: rgba(0, 0, 0, 0.02);
    border-top: 1px solid var(--material-border);
    display: flex; flex-direction: column; gap: 24px;
}

.stat-row { display: flex; gap: 40px; }
.apple-stat { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--text-sub); }
.stat-val { font-size: 1.4rem; font-weight: 700; }
.stat-val.red { color: var(--danger); }

.action-row { display: flex; gap: 12px; }
.action-row button { flex: 1; }

.apple-footer-bar { margin-top: 24px; padding: 16px; text-align: center; font-weight: 600; font-size: 0.95rem; border-radius: 18px; }
.apple-footer-bar a { color: var(--accent); text-decoration: none; }

.apple-toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px);
    background: #1c1c1e; color: white; padding: 12px 24px; border-radius: 16px; font-weight: 600;
    transition: 0.5s var(--spring-easing); opacity: 0; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.apple-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 700px) {
    .toolbar, .action-row { flex-direction: column; }
    .stat-row { justify-content: space-between; gap: 10px; }
    .top-nav { top: 20px; right: 20px; }
}
