:root {
  color-scheme: dark;
  --bg: oklch(0.12 0.012 294);
  --surface: oklch(0.17 0.018 294);
  --surface-strong: oklch(0.205 0.022 294);
  --surface-hover: oklch(0.245 0.03 294);
  --ink: oklch(0.98 0.004 294);
  --muted: oklch(0.75 0.02 294);
  --faint: oklch(0.59 0.025 294);
  --line: oklch(0.34 0.035 294);
  --primary: oklch(0.51 0.19 297);
  --primary-strong: oklch(0.43 0.18 297);
  --primary-soft: oklch(0.27 0.09 297);
  --violet-light: oklch(0.8 0.105 297);
  --danger: oklch(0.69 0.18 25);
  --focus: oklch(0.82 0.14 296);
  --shadow: oklch(0.04 0 0 / 0.36);
  --radius-sm: 8px;
  --radius-md: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; background: var(--bg); }
body { min-width: 320px; min-height: 100vh; min-height: 100dvh; margin: 0; color: var(--ink); background: var(--bg); text-rendering: optimizeLegibility; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.app { width: min(100%, 520px); min-height: 100vh; min-height: 100dvh; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom)); display: grid; align-content: center; gap: 14px; }
.brand { min-height: 82px; display: flex; align-items: center; gap: 14px; padding: 4px 8px 14px; border-bottom: 1px solid var(--line); }
.brand img { width: 84px; height: 72px; object-fit: contain; }
.brand h1, .brand p { margin: 0; }
.brand h1 { font-size: 1.45rem; line-height: 1.1; letter-spacing: -.035em; }
.brand p { margin-top: 4px; color: var(--muted); font-size: .78rem; }

.calculator { padding: clamp(18px, 5vw, 26px); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: 0 20px 50px var(--shadow); }
.period-selector { min-width: 0; margin: 0 0 20px; padding: 0; border: 0; }
.period-selector legend, .eyebrow { margin: 0 0 8px; color: var(--muted); font-size: .74rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.period-selector > div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.period-selector button { min-height: 48px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-strong); font-size: 1.15rem; font-weight: 800; cursor: pointer; }
.period-selector button:hover { background: var(--surface-hover); }
.period-selector button.is-active { border-color: var(--primary); background: var(--primary); color: white; }
.eyebrow { margin-bottom: 2px; }
.clock { display: block; width: 100%; margin: 4px 0 16px; color: var(--muted); font-size: clamp(2.15rem, 10vw, 3.2rem); font-weight: 750; line-height: 1; letter-spacing: -.05em; text-align: center; font-variant-numeric: tabular-nums; }

.result { margin-bottom: 20px; padding: 24px 20px 26px; overflow: hidden; border: 1px solid white; border-radius: var(--radius-md); color: oklch(0.18 0.025 294); background: white; box-shadow: 0 8px 24px var(--shadow); text-align: center; }
.result span { display: block; margin-bottom: 8px; color: var(--primary-strong); font-size: .86rem; font-weight: 850; letter-spacing: .045em; text-transform: uppercase; }
.result strong { display: block; font-size: clamp(2.75rem, 13vw, 4.1rem); font-weight: 850; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.result.invalid { border-color: oklch(0.82 0.12 25); background: oklch(0.94 0.035 25); }
.result.invalid span { color: oklch(0.48 0.17 25); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.keypad button { min-height: clamp(58px, 9vh, 72px); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-strong); box-shadow: 0 3px 7px var(--shadow); font-size: clamp(1.3rem, 6vw, 1.8rem); font-weight: 800; cursor: pointer; touch-action: manipulation; transition: background 140ms ease, transform 80ms ease; }
.keypad button:hover { background: var(--surface-hover); }
.keypad button:active { transform: translateY(2px); }
.keypad .action { color: var(--violet-light); background: var(--primary-soft); font-size: .9rem; }
.hint { min-height: 1.3em; margin: 15px 0 0; color: var(--faint); font-size: .76rem; text-align: center; }
.hint.error { color: oklch(0.82 0.12 25); font-weight: 700; }

@media (max-height: 740px) {
  .app { align-content: start; }
  .brand { min-height: 64px; }
  .brand img { width: 66px; height: 54px; }
  .calculator { padding-top: 16px; }
  .period-selector { margin-bottom: 14px; }
  .clock { font-size: 2.1rem; margin-bottom: 12px; }
  .result { margin-bottom: 14px; padding-block: 20px; }
  .keypad button { min-height: 50px; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
