/*
 * Martillomanía
 * Copyright (C) 2026 Miguel Rodríguez Saiz
 * SPDX-License-Identifier: GPL-3.0-only
 *
 * Tamaño de letra de los campos: 16px como mínimo para que Safari
 * no haga zoom al enfocar. touch-action: manipulation evita el zoom
 * por doble toque sin impedir el desplazamiento.
 */

:root {
  color-scheme: dark;
  --bg: #12151b;
  --card: #1c232e;
  --card-border: #313c4e;
  --inset: #10151c;
  --text: #f4f7fb;
  --muted: #c5d0dc;
  --line: #3a4658;
  --gold: #f0c14b;
  --gold-ink: #1c1406;
  --teal: #7eddd4;
  --teal-ink: #062422;
  --done: #d9ffe8;
  --done-bg: #123024;
  --danger: #ffb4b4;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.35;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button,
input,
label {
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button {
  user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.app {
  width: min(480px, 100%);
  margin: 0 auto;
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid #2a3340;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.logo {
  width: 36px;
  height: 36px;
  flex: none;
}

h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.now {
  margin: 4px 0 8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.98rem;
}

.lede {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.tools { display: flex; flex-direction: column; gap: 8px; }

.sort {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--inset);
}

.sort button,
#sound-toggle,
.ghost,
.open-btn,
.primary,
.step {
  font-size: 16px;
  white-space: nowrap;
}

.sort button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.sort button[aria-pressed="true"] {
  background: #2c384c;
  color: var(--text);
}

#sound-toggle {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

#sound-toggle[aria-pressed="false"] { color: #8b97a8; }

.sort-hint {
  margin: 8px 0 0;
  color: var(--teal);
  font-size: 0.92rem;
}

.save-error {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #3a2024;
  color: var(--danger);
}

main { padding: 12px 16px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  scroll-margin-top: 240px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.name-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  min-height: 44px;
  padding: 2px 4px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.name {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.name-hint {
  color: #9eabbd;
  font-size: 0.78rem;
  font-weight: 600;
}

.name-form { flex: 1; min-width: 0; }

.name-form input,
.fields input {
  width: 100%;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--inset);
  color: var(--text);
  font-size: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  caret-color: var(--gold);
}

.fields input::placeholder {
  color: #7f8b9c;
}

.name-form input { text-align: left; padding: 0 10px; margin-bottom: 8px; }

.th-step {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 14px;
  background: var(--inset);
  flex: none;
}

.step {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: #2a3546;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
}

.step:disabled { opacity: 0.35; }

.th-value {
  min-width: 54px;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.timer {
  position: relative;
  margin-top: 10px;
  padding: 10px 10px 10px 14px;
  border-radius: 14px;
  background: var(--inset);
  scroll-margin-top: 200px;
}

.timer::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent, var(--gold));
}

.timer[data-kind="potion"] { --accent: var(--gold); }
.timer[data-kind="boost"] { --accent: var(--teal); }

.timer-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
}

.timer[data-kind="potion"] .timer-title { color: #ffe3a3; }
.timer[data-kind="boost"] .timer-title { color: #c9fbf6; }

.phase-running .timer-title::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}

.idle-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
}

.idle-copy {
  grid-column: 1;
  grid-row: 2;
  margin: 2px 0 0;
  color: #9eabbd;
  font-size: 0.92rem;
}

.open-btn {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
}

.timer[data-kind="potion"] .open-btn { background: #3d3420; color: #ffe6ad; }
.timer[data-kind="boost"] .open-btn { background: #163432; color: #d7fffb; }

.remain,
.done-label {
  margin: 4px 0 0;
  font-size: clamp(1.45rem, 7vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.done-label { color: var(--done); }

.phase-done {
  background: var(--done-bg);
  --accent: #8ee0b0;
}

.ends {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
}

.fields label span {
  min-height: 2.3em;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  line-height: 1.15;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.actions > * { flex: 1 1 30%; }

.primary,
.ghost {
  min-height: 44px;
  border-radius: 12px;
}

.primary {
  border: 0;
  background: var(--gold);
  color: var(--gold-ink);
  font-weight: 800;
}

.timer[data-kind="boost"] .primary {
  background: var(--teal);
  color: var(--teal-ink);
}

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-weight: 600;
}

.ghost.danger {
  color: var(--danger);
  border-color: #6e3438;
}

.error {
  margin: 0 0 8px;
  color: var(--danger);
  font-size: 0.95rem;
  font-weight: 600;
}

button:active { filter: brightness(1.12); }
button:disabled { filter: none; }

footer {
  padding: 4px 16px calc(20px + env(safe-area-inset-bottom));
  color: #9eabbd;
  font-size: 0.88rem;
}

footer p { margin: 0 0 8px; }
.legal { color: #7f8b9c; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  margin: 16px;
  padding: 12px;
  border-radius: 12px;
  background: var(--card);
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

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