:root {
    --bg-color: #0a0a0c;
    --panel-bg: #141418;
    --text-color: #f3f4f6;
    --text-muted: #9ca3af;
    --accent-color: #ff3e3e;
    --accent-green: #00ff66;
    --accent-blue: #00e1ff;
    --border-color: #27272a;
    --font-display: 'Courier New', Courier, monospace;

    --graph-prepare: #f59e0b;
    --graph-work: #ef4444;
    --graph-rest: #3b82f6;
    --graph-countup: #8b5cf6;
}

[data-theme="light"] {
    --bg-color: #f4f4f5;
    --panel-bg: #ffffff;
    --text-color: #18181b;
    --text-muted: #71717a;
    --accent-color: #dc2626;
    --accent-green: #16a34a;
    --accent-blue: #2563eb;
    --border-color: #e4e4e7;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.3s, border-color 0.3s;
}

html, body {
    max-width: 100%;
    overflow-x: hidden; /* Absolutely prevents horizontal scrolling */
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px; /* Use strict pixels instead of rem for mobile boundaries */
    width: 100%;
    box-sizing: border-box; /* Forces padding to stay inside the width */
    -webkit-overflow-scrolling: touch;
}

/* Ensure all main containers respect the strict width */
.container, .display-panel, .config-panel {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Ensure the tabs row doesn't push the screen wider */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 5px; 
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

header {
    width: 100%;
    max-width: 1000px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

header h1 { font-size: 1.5rem; font-weight: 800; }
header h1 span { color: var(--accent-color); }

.theme-toggle {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.container {
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.display-panel {
    background: #000000;
    border: 4px solid #222;
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
    width: 100%;
}

.display-mode {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--accent-blue);
    font-weight: bold;
    letter-spacing: 2px;
}

.display-time {
    font-family: var(--font-display);
    font-size: 5rem;
    color: var(--accent-color);
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 62, 62, 0.3);
    line-height: 1;
    margin: 0.5rem 0;
}

.display-sub {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--accent-green);
    margin-bottom: 1rem;
}

.timeline-graph {
    display: flex;
    width: 100%;
    height: 12px;
    background: #222;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
    gap: 2px;
}

.segment {
    height: 100%;
    position: relative;
    opacity: 0.4;
    transition: opacity 0.3s;
}

.segment.active { opacity: 1; }
.segment.prepare { background: var(--graph-prepare); }
.segment.work { background: var(--graph-work); }
.segment.rest { background: var(--graph-rest); }
.segment.countup { background: var(--graph-countup); }

.segment .progress {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: rgba(255, 255, 255, 0.6);
    width: 0%;
    transition: width 1s linear;
}

.controls-row {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
}

.btn {
    flex: 1;
    padding: 1rem;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.btn-primary { background: var(--accent-color); color: white; }
.btn-success { background: var(--accent-green); color: #000; }
.btn-secondary { background: #4b5563; color: white; }

.config-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    width: 100%;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 5px; 
    width: 100%;
}

.tab-btn {
    flex: 0 0 auto; /* Prevent tabs from shrinking weirdly */
    min-width: 80px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 0.8rem 0.4rem;
    font-size: 0.8rem;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.tab-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.8rem;
    width: 100%;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.input-group label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 800;
    text-align: center;
}

.stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
}

.stepper-btn {
    background: var(--border-color);
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    font-weight: bold;
    width: 45px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.stepper-btn:active {
    background: var(--accent-color);
    color: white;
}

.stepper-val {
    font-size: 1.1rem;
    font-weight: bold;
    min-width: 30px;
    text-align: center;
}

/* Tablet / Desktop Overrides */
@media (min-width: 768px) {
    .container { max-width: 1000px; padding: 1rem; }
    .display-time { font-size: 7rem; }
}

@media (min-width: 900px) and (orientation: landscape) {
    .container {
        flex-direction: row;
        align-items: start;
    }
    .display-panel { position: sticky; top: 1rem; flex: 1.2; }
    .config-panel { flex: 1; }
}