:root {
    --bg: #e8f0ec;
    --surface: #ffffff;
    --ink: #1b2e26;
    --muted: #5a6f64;
    --line: #c3d3ca;
    --accent: #2f7a58;
    --accent-dark: #24604a;
    --focus: #f2a900;
    --danger: #b3392f;
    --danger-dark: #8f2d25;
}

html { -webkit-text-size-adjust: 100%; }

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    -webkit-tap-highlight-color: transparent;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    background: var(--bg);
    color: var(--ink);
}

/* Header */
.header {
    background: var(--accent);
    color: #ffffff;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 16px 20px;
    text-align: center;
    border-bottom: 6px solid var(--accent-dark);
}

.header h1 {
    margin: 0;
    letter-spacing: 3px;
}

.header p {
    margin: 4px 0 0;
}

/* Layout */
.page {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 640px;
    margin: 20px auto;
    padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Cards */
.card {
    background: var(--surface);
    padding: 20px;
    border-radius: 6px;
    border: 1px solid var(--line);
    border-top: 6px solid var(--accent);
    box-shadow: 0 8px 24px rgba(27, 46, 38, 0.08);
    min-width: 0;
}

.card h2 {
    margin: 0 0 8px;
    font-size: 1.05rem;
    color: var(--accent);
}

.card p { margin: 0; }

.big {
    font-size: 2rem;
    font-weight: bold;
}

.muted {
    color: var(--muted);
    margin-top: 10px !important;
}

/* Camera */
.stage {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    max-height: 68vh;
    max-height: 68dvh;
    background: var(--ink);
    border-radius: 4px;
    overflow: hidden;
}

.stage video,
.stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* mirror so it behaves like a mirror */
}

/* Big readouts on top of the camera, readable from a distance */
.hud {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px;
    pointer-events: none;
}

.hud-count {
    min-width: 64px;
    padding: 0 16px;
    border-radius: 8px;
    background: rgba(27, 46, 38, 0.7);
    color: #f2c57c;
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
}

.hud-feedback {
    align-self: stretch;
    padding: 8px 12px;
    border-radius: 6px;
    background: rgba(27, 46, 38, 0.8);
    color: #ffffff;
    font-size: 1.15rem;
    font-weight: 600;
    text-align: center;
}

.countdown {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(27, 46, 38, 0.35);
    color: #f2c57c;
    font-size: 7rem;
    font-weight: 700;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.countdown[hidden] { display: none; }

@media (orientation: landscape) {
    .stage { aspect-ratio: 4 / 3; }
}

/* Buttons */
button,
.button {
    display: inline-block;
    min-height: 48px;
    padding: 12px 18px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    font: inherit;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    color: #ffffff;
    transition: background 0.15s;
}

button:active,
.button:active { transform: translateY(1px); }

button:disabled {
    opacity: 0.6;
    cursor: default;
}

button:focus-visible,
.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 1px;
}

.button-row {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.button-row button { flex: 1; }

.button-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.primary,
#start-button { background: var(--accent); }
.primary:hover,
#start-button:hover { background: var(--accent-dark); }

#stop-button { background: var(--muted); }
#stop-button:hover { background: var(--ink); }

#sound-button {
    width: 100%;
    margin-top: 8px;
    background: #f8faf9;
    color: var(--ink);
    border: 1px solid var(--line);
}
#sound-button:hover { background: var(--line); }

#pain-button { background: var(--danger); width: 100%; }
#pain-button:hover { background: var(--danger-dark); }

/* Exercise switch */
.switch {
    display: flex;
    border: 1px solid var(--line);
    border-radius: 4px;
    overflow: hidden;
}

.switch button {
    flex: 1;
    border-radius: 0;
    background: #f8faf9;
    color: var(--ink);
}

.switch button:hover { background: var(--line); }
.switch button.active { background: var(--accent); color: #ffffff; }
.switch button.active:hover { background: var(--accent-dark); }

.narrow { max-width: 480px; }

/* Injury report form */
.form-page {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 12px;
}

form {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 28px 22px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 6px solid var(--accent);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(27, 46, 38, 0.08);
}

label {
    margin-top: 14px;
    font-size: 0.95rem;
    font-weight: 600;
}

label:first-of-type { margin-top: 0; }

input,
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    font: inherit;
    color: var(--ink);
    background: #f8faf9;
    border: 1px solid var(--line);
    border-radius: 4px;
}

input::placeholder,
textarea::placeholder { color: var(--muted); opacity: 0.8; }

input:hover,
select:hover,
textarea:hover { border-color: var(--accent); }

select {
    appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%231b2e26' stroke-width='2'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

textarea { min-height: 120px; resize: vertical; }

form button[type="submit"] {
    margin-top: 24px;
    background: var(--accent);
}

form button[type="submit"]:hover { background: var(--accent-dark); }

.back-link {
    margin-top: 14px;
    text-align: center;
    color: var(--accent);
}

/* Small phones */
@media (max-width: 480px) {
    .header { padding-bottom: 12px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
    .header h1 { font-size: 1.4rem; letter-spacing: 2px; }
    .header p { font-size: 0.85rem; }
    .page { gap: 12px; margin: 12px auto; }
    .card { padding: 16px; }
    .stats { gap: 12px; }
}

@media (max-width: 360px) {
    .stats { grid-template-columns: 1fr; }
}
