* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

:root {
  --bg: #000000;
  --text: #f7f7f2;
  --muted: #6f756c;
  --line: #161916;
  --red: #ff3131;
  --ring-off: #101210;
  --lcd: #ff3b3f;
  --lcd-dim: #6e1c20;
  --timer-size: 190px;
  --grid-gap: 10px;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #000;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

input {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.app {
  min-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
  background: #000;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 4px;
  min-height: 50px;
  margin-bottom: 4px;
  background: #000;
  transition: opacity .18s ease;
}

.title-button {
  border: 0;
  background: transparent;
  color: var(--text);
  min-height: 44px;
  padding: 0 8px;
  font-size: clamp(23px, 6.5vw, 33px);
  font-weight: 760;
  letter-spacing: -0.04em;
  cursor: pointer;
}

.plain-icon {
  border: 0;
  background: transparent;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 9px;
}

.plain-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.settings-icon {
  color: #ff4a4d;
}

.delete-icon {
  color: #60645e;
  transition: color .15s ease, transform .15s ease;
}

.delete-icon.holding {
  color: var(--red);
  transform: scale(.9);
}

.close-icon {
  color: var(--lcd);
  font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
  font-size: 30px;
  line-height: 1;
  padding: 0;
}

.timers-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 2), var(--timer-size));
  gap: var(--grid-gap);
  justify-content: center;
  align-content: start;
  justify-items: center;
  padding-top: 2px;
  padding-bottom: 8px;
}

.timer-item {
  width: var(--timer-size);
  height: var(--timer-size);
  display: grid;
  place-items: center;
}

.timer-shell {
  position: relative;
  width: var(--timer-size);
  height: var(--timer-size);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform .12s ease, opacity .12s ease;
  outline: none;
}

.timer-shell:active {
  transform: scale(.985);
}

.timer-shell.pending-delete {
  transform: scale(.92);
  opacity: .65;
}

.timer-shell.expired {
  animation: ringFlash .9s steps(2, end) infinite;
}

.timer-ring {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.sector {
  fill: none;
  stroke-width: 19;
  stroke-linecap: butt;
  stroke: var(--ring-off);
  transition: stroke .14s ease, opacity .14s ease;
}

.sector.active {
  stroke: var(--red);
}

.timer-core {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.table-number {
  font-size: clamp(22px, calc(var(--timer-size) * .235), 54px);
  line-height: .92;
  font-weight: 820;
  letter-spacing: -0.06em;
  white-space: nowrap;
}

.timer-time {
  margin-top: calc(var(--timer-size) * .035);
  color: #767a73;
  font-size: clamp(11px, calc(var(--timer-size) * .09), 18px);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.timer-shell.expired .timer-time,
.timer-shell.expired .table-number {
  color: var(--red);
}

.empty-state {
  min-height: 64dvh;
  display: grid;
  place-content: center;
  text-align: center;
  color: #424640;
  font-size: 14px;
  letter-spacing: .01em;
}

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  transform: translateX(-50%);
  background: #000;
  color: var(--lcd);
  border: 1px solid var(--lcd-dim);
  border-radius: 0;
  padding: 9px 12px;
  font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  text-transform: uppercase;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0,0,0,.72);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .22s ease, visibility 0s linear .22s;
}

.overlay.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.hidden {
  display: none !important;
}

/* Old-keypad-phone inspired menu — red LCD variant */
.panel {
  position: fixed;
  right: 0;
  top: 0;
  z-index: 20;
  width: min(96vw, 410px);
  height: 100dvh;
  background: #000;
  color: var(--lcd);
  border-left: 1px solid var(--lcd-dim);
  transform: translate3d(105%, 0, 0);
  opacity: .94;
  will-change: transform, opacity;
  transition: transform .32s cubic-bezier(.22, .72, .18, 1), opacity .24s ease;
  padding: max(15px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
  font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
}

.panel.open {
  transform: translate3d(0, 0, 0);
  opacity: 1;
}

.panel-head {
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--lcd-dim);
}

.panel h2 {
  margin: 0;
  color: var(--lcd);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.panel h2::before {
  content: "[ ";
}

.panel h2::after {
  content: " ]";
}

.panel-content {
  margin-top: 16px;
}

.sector-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.sector-tab {
  min-height: 44px;
  border: 1px solid var(--lcd-dim);
  border-radius: 0;
  background: #000;
  color: var(--lcd);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 1px 1px 0 rgba(255,59,63,.13), inset -1px -1px 0 rgba(110,28,32,.22);
}

.sector-tab::before {
  content: "SECTOR ";
  font-size: 10px;
  opacity: .72;
}

.sector-tab.active {
  background: var(--lcd);
  color: #000;
  border-color: var(--lcd);
}

.table-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.table-btn {
  min-height: 54px;
  border: 1px solid var(--lcd-dim);
  border-radius: 2px;
  background: #000;
  color: var(--lcd);
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 1px 1px 0 rgba(255,59,63,.14), inset -1px -1px 0 rgba(110,28,32,.24);
}

.table-btn:active {
  background: var(--lcd);
  color: #000;
}

.table-btn.active {
  color: #682326;
  border-color: #3b1719;
}

.settings-block {
  display: grid;
  gap: 10px;
}

.settings-label {
  color: var(--lcd);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  text-transform: uppercase;
}

#minutesInput {
  width: 100%;
  min-height: 54px;
  border-radius: 0;
  border: 1px solid var(--lcd-dim);
  background: #000;
  color: var(--lcd);
  font-family: inherit;
  font-size: 22px;
  padding: 0 12px;
  outline: none;
  box-shadow: inset 0 0 0 1px #16090a;
}

#minutesInput:focus {
  border-color: var(--lcd);
}

.settings-hint {
  color: var(--lcd-dim);
  font-size: 11px;
  line-height: 1.5;
}

/* Idle / DVD screensaver */
body.ambient-mode {
  overflow: hidden;
}

body.ambient-mode .topbar {
  opacity: 0;
  pointer-events: none;
}

body.ambient-mode .timers-grid {
  display: block;
}

body.ambient-mode .timer-item {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  margin: 0;
  will-change: transform;
  pointer-events: none;
}

body.ambient-mode .timer-shell {
  pointer-events: none;
}

@keyframes ringFlash {
  0%, 44% { opacity: 1; }
  45%, 72% { opacity: .48; }
  73%, 100% { opacity: 1; }
}

@media (max-width: 390px) {
  .app {
    padding-left: 8px;
    padding-right: 8px;
  }

  .table-buttons {
    gap: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .timer-shell.expired {
    animation: none;
  }
}
