:root {
  color-scheme: light;
  --bg: #fffdf8;
  --panel: #f7f1ed;
  --panel-2: #fbf7f3;
  --ink: #29282c;
  --muted: #6d6864;
  --line: #e6ddd6;
  --ready: #8f8b86;
  --running: #11985c;
  --paused: #e77b12;
  --done: #e2372f;
  --accent: #0b73ff;
  --sun: #ffbd00;
  --orange: #ff7a1a;
  --pink: #f45c9b;
  --purple: #8d65dd;
  --green: #28aa5b;
  --shadow: 0 4px 0 rgba(49, 45, 42, 0.16), 0 14px 26px rgba(45, 36, 28, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  width: 100%;
  max-width: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(255, 189, 0, 0.17) 0 96px, transparent 96px),
    linear-gradient(180deg, #fffdf8 0%, #f9fbff 58%, #fff9ec 100%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  opacity: 0.38;
}

.app-shell {
  width: min(900px, 100vw);
  max-width: 100vw;
  margin: 0 auto;
  padding: 8px max(8px, env(safe-area-inset-right)) 14px max(8px, env(safe-area-inset-left));
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 7px 9px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 4px 0 rgba(49, 45, 42, 0.08);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(20px, 5vw, 28px);
  min-width: 0;
  line-height: 1;
  letter-spacing: 0;
}

h1::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 61% 42%, var(--ink) 0 3px, transparent 4px),
    linear-gradient(180deg, var(--sun), var(--orange));
  box-shadow: inset 0 -5px 0 rgba(255, 122, 26, 0.42);
}

.topbar p {
  display: none;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.icon-button,
.primary-button,
.danger-button,
.ghost-button {
  border: 0;
  border-radius: 8px;
  min-height: 36px;
  cursor: pointer;
}

.icon-button {
  width: 36px;
  display: inline-grid;
  place-items: center;
  border: 2px solid transparent;
  background: var(--panel);
  color: var(--ink);
  font-size: 17px;
  box-shadow: 0 3px 0 rgba(49, 45, 42, 0.13);
}

.icon-button.active {
  background: #e8f1ff;
  color: var(--accent);
  border-color: #bcd8ff;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 0 9px;
  font-weight: 900;
  box-shadow: 0 4px 0 #0754bd;
}

.danger-button {
  background: #ffe3d4;
  color: #b93312;
  padding: 0 12px;
  font-weight: 900;
  box-shadow: 0 3px 0 rgba(185, 51, 18, 0.18);
}

.ghost-button {
  border: 2px solid #ebe1da;
  background: #fffaf6;
  color: var(--ink);
  padding: 0 10px;
  font-weight: 850;
  box-shadow: 0 3px 0 rgba(49, 45, 42, 0.1);
}

.timer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.timer-card {
  --state-color: var(--ready);
  position: relative;
  container-type: inline-size;
  overflow: hidden;
  min-height: 126px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  border: 2px solid #fff;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  isolation: isolate;
}

.timer-card::before {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: var(--progress, 0%);
  min-height: 0;
  background: color-mix(in srgb, var(--state-color) 18%, transparent);
  transition: height 240ms linear;
  z-index: -1;
}

.timer-card::after {
  content: "";
  position: absolute;
  top: -34px;
  right: -26px;
  width: 82px;
  height: 64px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--state-color) 18%, transparent);
  pointer-events: none;
}

.timer-card:nth-child(4n + 1) .avatar {
  --avatar-a: var(--sun);
  --avatar-b: var(--orange);
}

.timer-card:nth-child(4n + 2) .avatar {
  --avatar-a: #54d782;
  --avatar-b: #0b73ff;
}

.timer-card:nth-child(4n + 3) .avatar {
  --avatar-a: #ff8fc1;
  --avatar-b: #8d65dd;
}

.timer-card:nth-child(4n) .avatar {
  --avatar-a: #73e0ff;
  --avatar-b: #ffbd00;
}

.timer-card[data-state="ready"] {
  --state-color: var(--ready);
}

.timer-card[data-state="running"] {
  --state-color: var(--running);
}

.timer-card[data-state="paused"] {
  --state-color: var(--paused);
}

.timer-card[data-state="done"] {
  --state-color: var(--done);
  background: #fff0e9;
  animation: gentle-alert 1.25s ease-in-out infinite;
}

@keyframes gentle-alert {
  0%,
  100% {
    box-shadow: 0 4px 0 rgba(226, 55, 47, 0.28), 0 0 0 0 rgba(226, 55, 47, 0.22), 0 14px 26px rgba(45, 36, 28, 0.08);
  }
  50% {
    box-shadow: 0 4px 0 rgba(226, 55, 47, 0.28), 0 0 0 7px rgba(226, 55, 47, 0.08), 0 14px 26px rgba(45, 36, 28, 0.08);
  }
}

.card-main {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 7px;
  padding: 6px 8px 0;
}

.avatar {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, transparent 0 48%, rgba(255, 255, 255, 0.28) 48%),
    linear-gradient(135deg, var(--avatar-a, var(--sun)), var(--avatar-b, var(--orange)));
  color: #2b282d;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 950;
  overflow: hidden;
  box-shadow: inset 0 -5px 0 rgba(255, 255, 255, 0.24);
}

.avatar::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 6px;
  left: 9px;
  bottom: 6px;
  border-bottom: 2px solid rgba(43, 40, 45, 0.42);
  border-radius: 0 0 999px 999px;
}

.avatar img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar:has(img)::after {
  display: none;
}

.member-meta {
  min-width: 0;
}

.member-line {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 5px;
}

.member-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.member-name {
  max-width: 100%;
  font-size: 18px;
  line-height: 1.05;
  font-weight: 950;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-member {
  min-width: 28px;
  width: 28px;
  min-height: 28px;
  border: 0;
  background: #fffaf6;
  font-size: 14px;
  box-shadow: 0 3px 0 rgba(49, 45, 42, 0.1);
}

.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 18px;
  padding: 1px 6px;
  border-radius: 8px;
  background: #fffaf6;
  color: var(--state-color);
  font-size: 11px;
  font-weight: 950;
  white-space: nowrap;
}

.state-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--state-color);
}

.timer-face {
  display: grid;
  place-items: center;
  padding: 0 8px;
}

.time-left {
  width: 100%;
  color: var(--state-color);
  font-size: 52px;
  font-size: clamp(44px, 14.5cqw, 58px);
  font-variant-numeric: tabular-nums;
  font-weight: 950;
  line-height: 0.95;
  letter-spacing: 0;
  text-align: center;
}

.duration-note {
  min-height: 10px;
  margin-top: -3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  padding: 3px 8px 7px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.action-start,
.action-pause,
.action-clear,
.add-minute {
  min-width: 0;
  min-height: 34px;
  padding: 0 2px;
  overflow: hidden;
  font-size: 12px;
  white-space: nowrap;
}

.action-pause {
  color: var(--muted);
}

.add-minute {
  border-color: #f1ded2;
  background: #fffaf6;
  color: #6f5441;
}

.action-clear {
  background: #ffe3d4;
  color: #a92e12;
}

dialog {
  width: min(420px, calc(100vw - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: #fffdf8;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(54, 37, 23, 0.28);
}

dialog::backdrop {
  background: rgba(31, 23, 18, 0.42);
}

dialog form {
  padding: 14px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.dialog-head h2 {
  font-size: 22px;
  font-weight: 950;
}

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

.preset-button {
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 21px;
  font-weight: 950;
  box-shadow: 0 4px 0 rgba(49, 45, 42, 0.13);
}

.preset-button:nth-child(1) {
  background: #fff0de;
}

.preset-button:nth-child(2) {
  background: #eaf3ff;
}

.preset-button:nth-child(3) {
  background: #edf9ee;
}

.preset-button:nth-child(4) {
  background: #f4edff;
}

.preset-button:nth-child(5) {
  background: #fff6c9;
}

.custom-time,
.field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 850;
}

.custom-time input,
.field input[type="text"] {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-size: 19px;
  font-weight: 850;
}

.field input[type="file"] {
  width: 100%;
  color: var(--ink);
}

.avatar-preview {
  width: 74px;
  height: 74px;
  margin-top: 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--sun), var(--orange));
  overflow: hidden;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 950;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
}

.help-content {
  display: grid;
  gap: 10px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}

.help-content ol {
  margin: 0;
  padding-left: 22px;
}

.help-content li + li {
  margin-top: 4px;
}

.help-content a {
  color: var(--accent);
  font-weight: 900;
  text-decoration: none;
}

.help-owner {
  margin-top: 4px;
  font-weight: 900;
}

.full-width {
  width: 100%;
  margin-top: 10px;
  min-height: 50px;
}

@media (min-width: 860px) {
  .timer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 7px max(7px, env(safe-area-inset-right)) 12px max(7px, env(safe-area-inset-left));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 7px 9px;
    background: rgba(255, 253, 248, 0.9);
    backdrop-filter: blur(10px);
  }

  .top-actions {
    gap: 4px;
  }

  .icon-button {
    width: 32px;
    min-height: 34px;
    font-size: 16px;
  }

  .top-actions .primary-button {
    min-height: 34px;
    padding: 0 7px;
  }

  .timer-grid {
    gap: 6px;
  }

  .timer-card {
    min-height: 126px;
  }

  .time-left {
    font-size: 52px;
    font-size: clamp(44px, 14.5cqw, 58px);
  }
}

@media (max-width: 390px) {
  .card-main {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .avatar {
    width: 34px;
    height: 34px;
  }

  .member-name {
    font-size: 17px;
  }

  .card-actions {
    gap: 4px;
    padding-left: 7px;
    padding-right: 7px;
  }

  .action-start,
  .action-pause,
  .action-clear,
  .add-minute {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
