/* ---- Design tokens ---- */
:root {
  /* Warm kitchen palette */
  --accent: #E8590C;
  --accent-strong: #D14904;
  --accent-soft: #FFE7D6;
  --accent-2: #F97316;
  --bg: #FBF4EC;
  --bg-2: #F4E8DA;
  --card: #FFFFFF;
  --line: #ECDFD1;
  --text: #2A211C;
  --muted: #8C7E73;
  --danger: #C0392B;
  --danger-soft: #FCE7E3;
  --ok: #2E7D32;

  --radius: 16px;
  --radius-sm: 11px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(60, 35, 15, .06), 0 1px 3px rgba(60, 35, 15, .05);
  --shadow: 0 1px 2px rgba(60, 35, 15, .05), 0 12px 28px -14px rgba(60, 35, 15, .22);
  --shadow-lg: 0 24px 60px -20px rgba(40, 20, 8, .38);
  --ring: 0 0 0 3px rgba(232, 89, 12, .32);
  --ease: cubic-bezier(.2, .8, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #FB7A38;
    --accent-strong: #F26417;
    --accent-soft: #3A2417;
    --accent-2: #FB923C;
    --bg: #161211;
    --bg-2: #1E1815;
    --card: #241D19;
    --line: #382D26;
    --text: #F3EAE1;
    --muted: #A99A8D;
    --danger: #F0857A;
    --danger-soft: #3A1E1B;
    --ok: #7BC47F;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 14px 30px -16px rgba(0, 0, 0, .7);
    --shadow-lg: 0 24px 60px -18px rgba(0, 0, 0, .8);
    --ring: 0 0 0 3px rgba(251, 122, 56, .38);
  }
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 620px at 100% -8%, var(--bg-2), transparent 60%),
    radial-gradient(900px 520px at -6% 0%, var(--bg-2), transparent 55%);
  background-attachment: fixed;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent-strong));
  color: #fff;
  position: sticky; top: 0; z-index: 10;
  box-shadow: 0 6px 22px -12px rgba(180, 70, 10, .8);
}
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar a {
  color: #fff; text-decoration: none; padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-weight: 600; letter-spacing: .01em; opacity: .82;
  transition: background .18s var(--ease), opacity .18s var(--ease);
}
.topbar a:hover { opacity: 1; background: rgba(255, 255, 255, .14); }
.topbar a.active {
  background: rgba(255, 255, 255, .24); opacity: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
}
.icon-btn {
  background: rgba(255, 255, 255, .12); border: none; color: #fff;
  font-size: 20px; cursor: pointer; width: 40px; height: 40px;
  border-radius: var(--radius-pill); display: grid; place-items: center;
  transition: background .18s var(--ease), transform .18s var(--ease);
}
.icon-btn:hover { background: rgba(255, 255, 255, .24); }
.icon-btn:active { transform: scale(.94); }
#sync-pill {
  font-size: 12px; font-weight: 600; padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .2); color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}

main { max-width: 640px; margin: 0 auto; padding: 20px 16px 40px; }
button { font: inherit; cursor: pointer; color: inherit; }

/* Shared focus ring */
:where(button, input, a, [tabindex]):focus-visible {
  outline: none; box-shadow: var(--ring);
}

/* ---- Ad-hoc timer form ---- */
#adhoc-form {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow-sm); margin-bottom: 4px;
}
#adhoc-form input {
  font: inherit; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); min-height: 46px;
  background: var(--bg); color: var(--text);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
#adhoc-form input::placeholder { color: var(--muted); }
#adhoc-form input:focus { border-color: var(--accent); }
#adhoc-label { width: 100%; margin-bottom: 10px; }
.preset-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.preset-row .preset, .toolbar button {
  padding: 10px 16px; border: 1px solid var(--line);
  border-radius: var(--radius-pill); background: var(--bg);
  min-height: 46px; font-weight: 600; color: var(--text);
  transition: transform .12s var(--ease), border-color .18s var(--ease), background .18s var(--ease);
}
.preset-row .preset:hover, .toolbar button:hover {
  border-color: var(--accent); background: var(--accent-soft);
}
.preset-row .preset:active, .toolbar button:active { transform: translateY(1px) scale(.98); }

#adhoc-start {
  padding: 11px 22px; min-height: 46px; border: none;
  border-radius: var(--radius-sm); font-weight: 700; letter-spacing: .01em;
  color: #fff; background: linear-gradient(135deg, var(--accent-2), var(--accent-strong));
  box-shadow: 0 8px 18px -8px rgba(232, 89, 12, .7);
  transition: transform .12s var(--ease), box-shadow .18s var(--ease), filter .18s var(--ease);
}
#adhoc-start:hover { filter: brightness(1.05); box-shadow: 0 10px 22px -8px rgba(232, 89, 12, .8); }
#adhoc-start:active { transform: translateY(1px) scale(.98); }

.error { color: var(--danger); margin-top: 10px; font-weight: 500; }
.empty { color: var(--muted); text-align: center; margin: 40px 0; }
ul { list-style: none; padding: 0; }

/* ---- Timer cards ---- */
.timer-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 18px 16px; margin-top: 14px;
  box-shadow: var(--shadow);
  animation: card-in .32s var(--ease) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.timer-card .row1 { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.timer-card .label {
  font-weight: 700; font-size: 16px; overflow-wrap: anywhere;
  color: var(--text);
}
.timer-card .time {
  font-variant-numeric: tabular-nums; font-size: 40px; font-weight: 800;
  letter-spacing: -.02em; line-height: 1; color: var(--text);
  transition: color .2s var(--ease);
}
.timer-card .time.paused { color: var(--muted); }

.timer-card progress {
  width: 100%; height: 10px; margin: 14px 0 16px;
  border: none; border-radius: var(--radius-pill); overflow: hidden;
  background: var(--bg-2); appearance: none; -webkit-appearance: none;
}
.timer-card progress::-webkit-progress-bar { background: var(--bg-2); border-radius: var(--radius-pill); }
.timer-card progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--accent-2), var(--accent-strong));
  border-radius: var(--radius-pill); transition: width .95s linear;
}
.timer-card progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--accent-2), var(--accent-strong));
  border-radius: var(--radius-pill);
}

.timer-card .controls { display: flex; gap: 8px; }
.timer-card .controls button {
  flex: 1; min-height: 46px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--bg); font-weight: 600;
  transition: transform .12s var(--ease), background .18s var(--ease), border-color .18s var(--ease);
}
.timer-card .controls button:hover { background: var(--accent-soft); border-color: var(--accent); }
.timer-card .controls button:active { transform: translateY(1px) scale(.98); }
.timer-card .controls .cancel { color: var(--danger); }
.timer-card .controls .cancel:hover { background: var(--danger-soft); border-color: var(--danger); }

/* Finishing soon: last 10 seconds */
.timer-card.urgent {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 1px var(--accent);
}
.timer-card.urgent .time { color: var(--accent); animation: pulse 1s var(--ease) infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

/* ---- Recipes ---- */
.recipe-item {
  display: flex; align-items: center; gap: 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; margin-top: 12px; box-shadow: var(--shadow-sm);
  transition: transform .14s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.recipe-item:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--accent); }
.recipe-item .ricon {
  font-size: 26px; width: 48px; height: 48px; flex: none;
  display: grid; place-items: center; border-radius: 13px;
  background: var(--accent-soft);
}
.recipe-item a { color: inherit; text-decoration: none; font-weight: 700; flex: 1; }
.recipe-item .del {
  background: none; border: none; font-size: 18px; opacity: .6;
  border-radius: 10px; width: 40px; height: 40px;
  transition: opacity .18s var(--ease), background .18s var(--ease);
}
.recipe-item .del:hover { opacity: 1; background: var(--danger-soft); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.toolbar h2 { font-size: 22px; letter-spacing: -.01em; }

/* ---- Recipe steps ---- */
.step-item {
  display: flex; gap: 12px; align-items: center; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 14px; margin-top: 9px; box-shadow: var(--shadow-sm);
}
.step-item .snum { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.step-item .stext { flex: 1; overflow-wrap: anywhere; }
.step-item .dur {
  color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600;
  background: var(--bg-2); padding: 3px 9px; border-radius: var(--radius-pill); font-size: 13px;
}
.step-item .start-step {
  background: linear-gradient(135deg, var(--accent-2), var(--accent-strong));
  color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 10px 16px; min-height: 44px; font-weight: 700;
  box-shadow: 0 6px 14px -7px rgba(232, 89, 12, .7);
  transition: transform .12s var(--ease), filter .18s var(--ease);
}
.step-item .start-step:hover { filter: brightness(1.05); }
.step-item .start-step:active { transform: translateY(1px) scale(.97); }

/* ---- Alarm overlay ---- */
#alarm-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(120% 120% at 50% 0%, rgba(210, 60, 15, .97), rgba(150, 30, 5, .98));
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; color: #fff;
  animation: fade-in .2s var(--ease) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
#alarm-overlay[hidden] { display: none; }
.alarm-box { text-align: center; padding: 24px; width: min(480px, 92vw); }
.alarm-box h2 {
  font-size: 38px; margin-bottom: 18px; letter-spacing: -.01em;
  animation: bell 1.1s var(--ease) infinite;
}
@keyframes bell {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-8deg); }
  40% { transform: rotate(6deg); }
  60% { transform: rotate(-4deg); }
  80% { transform: rotate(2deg); }
}
.alarm-box li {
  background: rgba(255, 255, 255, .14); border-radius: var(--radius);
  padding: 18px; margin-top: 14px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.alarm-box .alabel { font-size: 22px; font-weight: 800; display: block; margin-bottom: 12px; }
.alarm-box button {
  min-height: 48px; padding: 0 24px; border-radius: var(--radius-sm); border: none;
  font-weight: 700; margin: 0 6px;
  transition: transform .12s var(--ease), filter .18s var(--ease);
}
.alarm-box button:active { transform: scale(.96); }
.alarm-box .dismiss { background: #fff; color: var(--danger); }
.alarm-box .repeat { background: rgba(255, 255, 255, .22); color: #fff; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3); }

/* ---- Settings dialog ---- */
dialog#settings {
  border: none; border-radius: 20px; padding: 24px;
  width: min(440px, 92vw); background: var(--card); color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog#settings::backdrop { background: rgba(30, 15, 5, .5); backdrop-filter: blur(2px); }
dialog#settings h2 { font-size: 20px; margin-bottom: 6px; }
dialog#settings label { display: block; font-weight: 600; margin-top: 14px; margin-bottom: 4px; }
dialog#settings .hint { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
dialog#settings input[type=url], dialog#settings input[type=password] {
  width: 100%; font: inherit; padding: 11px 13px; min-height: 46px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text);
}
dialog#settings input:focus { border-color: var(--accent); outline: none; }
dialog#settings .toolbar { margin-top: 18px; margin-bottom: 0; }
dialog#settings .toolbar button, dialog#settings button {
  padding: 10px 16px; min-height: 44px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); font-weight: 600;
}
dialog#settings button:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---- Version footer ---- */
#version-footer { margin-top: 44px; text-align: center; color: var(--muted); font-size: 12px; }
#version-footer code { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
#version-footer button {
  border: 1px solid var(--line); background: var(--card); color: var(--accent);
  font-size: 12px; font-weight: 600; padding: 5px 12px;
  border-radius: var(--radius-pill); margin-left: 6px;
}
#version-footer button:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---- Recipe editor ---- */
.editor input[type=text] {
  width: 100%; font: inherit; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text);
}
.editor input:focus { border-color: var(--accent); outline: none; }
.editor .step-edit { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.editor .step-edit input.stext-in { flex: 1; }
.editor .step-edit input.sdur-in { width: 92px; }
.editor .step-edit button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  min-width: 40px; min-height: 40px; font-weight: 600;
}
.editor .step-edit button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.editor .step-edit button:disabled { opacity: .4; cursor: not-allowed; }

.emoji-grid { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.emoji-grid button {
  font-size: 22px; border: 1px solid var(--line); background: var(--card);
  border-radius: var(--radius-sm); width: 46px; height: 46px;
  transition: transform .12s var(--ease), border-color .18s var(--ease);
}
.emoji-grid button:hover { transform: translateY(-1px); border-color: var(--accent); }
.emoji-grid button.sel { border-color: var(--accent); background: var(--accent-soft); box-shadow: var(--ring); }

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
