/*
   TIP CALCULATOR - EXPERT WEB TOOLS
*/

@font-face { font-family: 'Inter';       src: url('/fonts/inter-v20-latin-regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Orbitron';    src: url('/fonts/orbitron-v35-latin-700.woff2')  format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Roboto Mono'; src: url('/fonts/roboto-mono-v31-latin-regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }

:root {
    --bg-dark:          #0a0a0f;
    --primary-accent:   #3b82f6;
    --secondary-accent: #8b5cf6;
    --text-main:        #ffffff;
    --text-muted:       #94a3b8;
    --card-bg:          rgba(25, 25, 35, 0.6);
    --card-border:      rgba(255, 255, 255, 0.08);
    --input-bg:         rgba(255, 255, 255, 0.05);
    --font-heading:     'Orbitron', sans-serif;
    --font-body:        'Inter', sans-serif;
    --font-code:        'Roboto Mono', monospace;
}

/* Light Theme Variables */
html.light-theme {
    --bg-dark:          #f8fafc;
    --primary-accent:   #2563eb;
    --secondary-accent: #7c3aed;
    --text-main:        #0f172a;
    --text-muted:       #475569;
    --card-bg:          #ffffff;
    --card-border:      rgba(0, 0, 0, 0.1);
    --input-bg:         rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* FIX: Removed overflow-x: hidden for strict mobile accessibility */
html, body {
    width: 100%;
    max-width: 100vw;
    transition: background-color 0.2s ease;
}

::-webkit-scrollbar        { width: 10px; height: 10px; }
::-webkit-scrollbar-track  { background: rgba(0,0,0,0.1); border-radius: 5px; }
::-webkit-scrollbar-thumb  { background: rgba(150,150,150,0.3); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(150,150,150,0.5); }

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

/* --- Accessibility --- */
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}

.background-glow {
    position: fixed; top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle at center, rgba(59,130,246,0.08) 0%, rgba(10,10,15,0) 50%);
    z-index: -1; pointer-events: none;
}
html.light-theme .background-glow {
    background: radial-gradient(circle at center, rgba(37,99,235,0.05) 0%, transparent 50%);
}

/* --- Header --- */
.tool-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.5rem 5%; max-width: 1400px; margin: 0 auto; width: 100%;
    flex-wrap: wrap; gap: 8px;
}
.header-right {
    display: flex; align-items: center; gap: 1rem;
}
.back-btn {
    color: var(--text-muted); text-decoration: none;
    display: flex; align-items: center; gap: 8px; transition: color 0.3s;
    border-radius: 4px; padding: 2px 4px;
}
.back-btn:hover         { color: var(--primary-accent); }
.back-btn:focus-visible { outline: 2px solid var(--primary-accent); color: var(--primary-accent); }
.logo      { font-family: var(--font-heading); font-size: 1.2rem; }
.logo span { color: var(--primary-accent); }

/* Theme Toggle Button */
.theme-toggle-btn {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 1.25rem; transition: color 0.2s; padding: 6px;
    display: flex; align-items: center; justify-content: center;
}
.theme-toggle-btn:hover         { color: var(--primary-accent); }
.theme-toggle-btn:focus-visible { outline: 2px solid var(--primary-accent); border-radius: 4px; }

/* --- Main Layout --- */
.main-content { flex-grow: 1; padding: 2rem 5%; max-width: 900px; margin: 0 auto; width: 100%; }
.tool-container { display: flex; justify-content: center; }
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; width: 100%; }

/* Card */
.card {
    background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 16px; padding: 2rem;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 15px 50px rgba(0,0,0,0.1);
}
.card h2 {
    font-family: var(--font-heading); font-size: 1.1rem; color: var(--text-muted);
    margin-bottom: 1.5rem; display: flex; align-items: center; gap: 10px;
}
.card h2 i { color: var(--primary-accent); }

/* Inputs */
.input-group       { margin-bottom: 1.5rem; }
.input-group label { display: block; font-size: 0.9rem; color: var(--text-muted); margin-bottom: 8px; }

.currency-input         { position: relative; display: flex; align-items: center; }
.currency-input span    { position: absolute; left: 15px; color: var(--text-muted); font-size: 1.1rem; pointer-events: none; }
.currency-input input   { padding-left: 30px; }

input[type="number"], input[type="text"] {
    width: 100%; background-color: var(--input-bg); border: 1px solid var(--card-border);
    color: var(--text-main); padding: 12px; border-radius: 8px; font-size: 1.2rem;
    outline: none; font-family: var(--font-code); transition: border-color 0.2s;
    -moz-appearance: textfield; appearance: textfield;
}
input[type="number"]:focus, input[type="text"]:focus { border-color: var(--primary-accent); }
input[type="number"]:focus-visible, input[type="text"]:focus-visible { outline: 2px solid var(--primary-accent); }

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.people-control input[type="number"] { text-align: center; }
#billAmount { text-align: right; }

/* Tip Grid */
.tip-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.tip-btn {
    background: var(--input-bg); border: 1px solid var(--card-border); color: var(--text-main);
    padding: 10px; border-radius: 6px; cursor: pointer; font-size: 0.95rem;
    font-weight: 600; transition: all 0.2s; font-family: var(--font-body);
    min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.tip-btn:hover         { background: rgba(150,150,150,0.1); border-color: var(--primary-accent); }
.tip-btn.active        { background: var(--primary-accent); color: #fff; border-color: var(--primary-accent); }
.tip-btn:focus-visible { outline: 2px solid var(--primary-accent); }

/* Custom tip input */
.tip-btn.custom {
    grid-column: 1 / -1; text-align: center; font-size: 0.95rem; min-height: 44px;
    background-color: var(--input-bg); padding: 10px; width: 100%; color: var(--text-main);
    font-family: var(--font-code); appearance: textfield; -moz-appearance: textfield;
}
.tip-btn.custom::placeholder { color: var(--text-muted); font-family: var(--font-body); }
.tip-btn.custom:focus         { border-color: var(--primary-accent); outline: none; }
.tip-btn.custom:focus-visible { outline: 2px solid var(--primary-accent); }
/* Highlight state when valid custom tip is active */
.tip-btn.custom.active-custom { border-color: var(--primary-accent); background: rgba(59,130,246,0.05); }

/* People Control */
.people-control { display: flex; align-items: center; gap: 10px; }
.people-control input { flex: 1; }

.round-btn {
    width: 44px; height: 44px; border-radius: 50%;
    border: 1px solid var(--card-border);
    background: transparent; color: var(--text-main); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s; flex-shrink: 0;
}
.round-btn:hover         { background: rgba(150,150,150,0.1); }
.round-btn:focus-visible { outline: 2px solid var(--primary-accent); }

/* Checkbox */
.mt-1 { margin-top: 1.5rem; }
.checkbox-wrapper {
    display: flex; align-items: flex-start; gap: 10px;
    color: var(--text-main); cursor: pointer; font-size: 0.95rem; user-select: none;
}
.checkbox-wrapper input {
    accent-color: var(--primary-accent); width: 16px; height: 16px;
    cursor: pointer; flex-shrink: 0; margin-top: 2px;
}
.checkbox-wrapper:focus-within { outline: 2px solid var(--primary-accent); border-radius: 4px; }
.checkbox-wrapper small { color: var(--text-muted); font-size: 0.8rem; }

/* Result Section */
.result-section {
    background: var(--input-bg);
    display: flex; flex-direction: column; justify-content: space-between;
}

.result-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 2rem;
}
.result-row .label {
    color: var(--text-main); font-weight: 600;
    display: flex; flex-direction: column; font-size: 0.9rem;
}
.result-row .label span { font-size: 0.75rem; color: var(--text-muted); }

/* FIX: Allow extreme numbers to safely scroll instead of breaking mobile layout */
.scrollable-amount {
    overflow-x: auto; white-space: nowrap; -ms-overflow-style: none; scrollbar-width: none;
}
.scrollable-amount::-webkit-scrollbar { display: none; }

.result-row .amount {
    font-family: var(--font-heading);
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    color: var(--primary-accent); font-weight: 700;
}
.result-row .amount.small {
    font-size: clamp(1.1rem, 4vw, 1.5rem);
    color: var(--secondary-accent);
}

.copyable {
    cursor: pointer; transition: opacity 0.2s, transform 0.1s;
    position: relative; border-radius: 4px; padding: 2px 4px;
}
.copyable:hover  { opacity: 0.8; }
.copyable:active { transform: scale(0.95); }
.copyable:focus-visible { outline: 2px solid var(--primary-accent); }

.copyable::after {
    content: '\29C9';
    font-size: 0.75rem; color: var(--text-muted);
    position: absolute; right: -18px; top: 50%;
    transform: translateY(-50%); opacity: 0; transition: opacity 0.2s;
    pointer-events: none;
}
.copyable:hover::after { opacity: 1; }

.reset-btn {
    background: rgba(59,130,246,0.1); color: var(--primary-accent);
    border: 1px solid rgba(59,130,246,0.3);
    width: 100%; padding: 12px; border-radius: 6px; font-weight: 700;
    cursor: pointer; transition: background 0.2s; margin-top: auto;
    font-family: var(--font-body); min-height: 44px;
}
.reset-btn:hover         { background: rgba(59,130,246,0.2); }
.reset-btn:focus-visible { outline: 2px solid var(--primary-accent); }

/* Toast */
.toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: #1e1e24; border: 1px solid var(--primary-accent);
    color: #fff; padding: 10px 20px; border-radius: 8px; z-index: 2000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5); font-size: 0.9rem;
    white-space: nowrap; opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
}
.toast.toast-visible { opacity: 1; pointer-events: auto; }
html.light-theme .toast { background: #ffffff; color: #0f172a; border-color: var(--primary-accent); }

.hidden { display: none !important; }

/* Info Section */
.info-section    { margin-top: 4rem; padding: 0 1rem; }
.info-section h2 { font-family: var(--font-heading); color: var(--text-main); margin-bottom: 2rem; font-size: 1.5rem; text-align: center; }
.info-grid       { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 2rem; margin-bottom: 2rem; }
.info-grid h3    { color: var(--primary-accent); font-family: var(--font-heading); font-size: 1.1rem; margin-bottom: 0.5rem; }
.info-grid i     { margin-right: 8px; }
.info-grid p     { color: var(--text-muted); font-size: 0.95rem; line-height: 1.6; }

.faq-container    { margin-top: 2rem; background: var(--card-bg); padding: 2rem; border-radius: 16px; border: 1px solid var(--card-border); }
.faq-container h3 { font-family: var(--font-heading); color: var(--text-main); margin-bottom: 1.5rem; border-bottom: 1px solid var(--card-border); padding-bottom: 0.5rem; }
.faq-container h4 { color: var(--secondary-accent); font-size: 1rem; margin-bottom: 0.5rem; margin-top: 1.5rem; font-family: var(--font-body); }
.faq-container p  { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 1rem; line-height: 1.6; }

footer       { text-align: center; padding: 3rem 0; color: var(--text-muted); font-size: 0.9rem; border-top: 1px solid var(--card-border); margin-top: 3rem; }
footer a     { color: var(--text-main); text-decoration: none; }
footer a:hover { color: var(--primary-accent); }

/* === RESPONSIVE === */
@media (max-width: 600px) {
    .calc-grid     { grid-template-columns: 1fr; }
    .copyable::after { display: none; }
    .tip-grid      { grid-template-columns: repeat(2, 1fr); }
    .tip-btn.custom { grid-column: 1 / -1; }
    .main-content, .tool-header { padding: 1.5rem 1rem; }
    .card          { padding: 1.5rem; }
    .result-row    { margin-bottom: 1.5rem; }
}

@media (max-width: 480px) {
    .tool-header   { flex-direction: column; align-items: flex-start; }
    .card          { padding: 1.25rem; border-radius: 12px; }
    .tip-grid      { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .result-row    { flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 1.25rem; }
    .result-row .amount { align-self: flex-end; }
    .info-grid     { grid-template-columns: 1fr; }
    .faq-container { padding: 1.5rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration:  0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}