:root {
  color-scheme: dark;
  --background: #050505;
  --surface: #171717;
  --surface-hover: #202020;
  --accent: #ff9800;
  --accent-soft: rgb(255 152 0 / 14%);
  --ink: #f4f4f4;
  --muted: #999999;
  --line: #303030;
  --danger: #ff6674;
  --shadow: 0 14px 36px rgb(0 0 0 / 34%);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--background);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--background);
  -webkit-tap-highlight-color: transparent;
}

button,
input { font: inherit; }

button { color: inherit; }

.app-shell {
  display: flex;
  width: min(100%, 620px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px calc(78px + env(safe-area-inset-bottom));
  flex-direction: column;
}

.app-header {
  margin-bottom: 10px;
  text-align: center;
}

.brand {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .16em;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.55rem, 6vw, 2rem);
  line-height: 1.25;
  letter-spacing: .02em;
}

.clock-panel { width: 100%; }

.reference-toolbar {
  display: flex;
  min-height: 32px;
  margin: 0 8px 6px 10px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.live-control {
  display: flex;
  width: fit-content;
  min-height: 32px;
  margin: 0;
  align-items: center;
  gap: 7px;
  color: #c8c8c8;
  cursor: pointer;
  font-size: .76rem;
  font-weight: 700;
  user-select: none;
  white-space: nowrap;
}

.live-control input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
}

.reference-label {
  margin: 0;
  color: var(--accent);
  font-size: .84rem;
  font-weight: 800;
  letter-spacing: .06em;
}

.cards {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 12px;
}

.time-card {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  height: 128px;
  min-height: 128px;
  max-height: 128px;
  padding: 10px 14px 8px 38px;
  grid-template-rows: 56px 46px;
  align-content: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: linear-gradient(145deg, #1b1b1b, #151515);
  box-shadow: var(--shadow);
  transition: border-color .16s ease, opacity .16s ease, transform .16s ease;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.time-card:focus-within { border-color: rgb(255 152 0 / 55%); }

.drag-handle {
  position: absolute;
  inset: 0 auto 0 0;
  width: 27px;
  border: 0;
  border-right: 1px solid rgb(255 152 0 / 24%);
  border-radius: 16px 0 0 16px;
  background: var(--accent-soft);
  cursor: grab;
  touch-action: none;
}

.drag-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 36px;
  border-radius: 99px;
  background: repeating-linear-gradient(to bottom, var(--accent) 0 4px, transparent 4px 8px);
  transform: translate(-50%, -50%);
}

.drag-handle:active { cursor: grabbing; }

.drag-source {
  border-color: rgb(255 152 0 / 65%);
  opacity: .2;
}

.drag-ghost {
  position: fixed !important;
  z-index: 1000;
  margin: 0 !important;
  opacity: .62;
  pointer-events: none;
  transform: scale(1.018);
  box-shadow: 0 22px 48px rgb(0 0 0 / 65%);
  transition: none !important;
}

.card-location {
  display: grid;
  min-width: 0;
  height: 56px;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: 28px 28px;
  align-items: center;
  column-gap: 7px;
}

.zone-button {
  height: 28px;
  min-width: 0;
  padding: 0 4px;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.country-button {
  display: block;
  grid-column: 1;
  grid-row: 1;
  color: #eeeeee;
  font-size: clamp(.96rem, 4.3vw, 1.12rem);
  font-weight: 760;
}

.country-name,
.region-name {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.region-button {
  display: flex;
  grid-column: 1;
  grid-row: 2;
  align-items: baseline;
  gap: 6px;
  color: #d0d0d0;
  font-size: clamp(.84rem, 3.8vw, .96rem);
  font-weight: 680;
}

.region-name { flex: 0 1 auto; }

.utc-offset {
  flex: 0 0 auto;
  color: #a8a8a8;
  font-size: .68rem;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
}

.zone-button:active,
.zone-button:focus-visible {
  outline: 0;
  background: var(--surface-hover);
}

.remove-button {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--danger);
  font-size: 1.25rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
}

.remove-placeholder {
  grid-column: 2;
  grid-row: 1;
  width: 28px;
  height: 28px;
}

.remove-button:active,
.remove-button:focus-visible {
  outline: 0;
  background: rgb(255 102 116 / 10%);
}

.time-row {
  display: grid;
  min-width: 0;
  height: 46px;
  margin-top: 0;
  grid-template-columns: minmax(0, 1.25fr) minmax(104px, .75fr);
  align-items: center;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}

.date-text,
.time-text {
  overflow: hidden;
  color: var(--ink);
  line-height: 1.08;
  text-overflow: clip;
  white-space: nowrap;
}

.date-text {
  font-size: clamp(1.42rem, 6.6vw, 2rem);
  font-weight: 480;
  letter-spacing: -.025em;
}

.time-text {
  font-size: clamp(1.68rem, 7.8vw, 2.35rem);
  font-weight: 700;
  letter-spacing: -.025em;
  text-align: right;
}

.picker-field {
  position: relative;
  display: block;
  min-width: 0;
  height: 46px;
  min-height: 46px;
  padding: 3px;
  border-bottom: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.picker-field:focus-within {
  border-bottom-color: var(--accent);
  background: rgb(255 255 255 / 3%);
}

.picker-field .date-text,
.picker-field .time-text {
  display: flex;
  height: 100%;
  align-items: center;
}

.picker-field .time-text { justify-content: flex-end; }

.date-input,
.time-input {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.dst-slot {
  display: flex;
  grid-column: 2;
  grid-row: 2;
  height: 24px;
  min-width: 28px;
  min-height: 24px;
  align-items: center;
  justify-content: flex-end;
}

.dst-button {
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid rgb(255 152 0 / 42%);
  border-radius: 999px;
  background: var(--accent-soft);
  color: #ffc062;
  font-size: .75rem;
  font-weight: 750;
  cursor: pointer;
}

.dst-button[data-mode="ignored"] {
  border-color: rgb(255 193 7 / 58%);
  background: rgb(255 193 7 / 14%);
  color: #ffd45e;
}

.dst-placeholder { min-height: 24px; }

.card-divider {
  display: grid;
  margin: 4px 0 1px;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 11px;
  color: #c78320;
  font-size: .69rem;
  font-weight: 750;
  letter-spacing: .08em;
}

.card-divider::before,
.card-divider::after {
  content: "";
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent));
  opacity: .8;
}

.card-divider::after { background: linear-gradient(90deg, var(--accent), transparent); }

.add-button {
  display: flex;
  width: min(72%, 300px);
  min-height: 50px;
  margin: 20px auto 0;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid #343434;
  border-radius: 14px;
  background: #191919;
  color: var(--accent);
  box-shadow: 0 8px 20px rgb(0 0 0 / 28%);
  font-size: .93rem;
  font-weight: 750;
  cursor: pointer;
}

.add-button span:first-child {
  font-size: 1.35rem;
  line-height: 1;
}

.add-button:active,
.add-button:focus-visible {
  border-color: var(--accent);
  outline: 0;
  background: #202020;
  transform: translateY(1px);
}

.drag-help {
  margin: 14px auto 0;
  color: #737373;
  font-size: .72rem;
  line-height: 1.55;
  text-align: center;
}

.site-footer {
  margin-top: auto;
  padding-top: 28px;
  text-align: center;
}

.mrs-tools-link {
  display: inline-block;
  padding: 6px 10px;
  color: #8b8b8b;
  font-size: .78rem;
  letter-spacing: .08em;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color .16s ease;
}

.mrs-tools-link:hover,
.mrs-tools-link:focus-visible {
  color: #d0d0d0;
  outline: 0;
}

.ad-banner {
  position: fixed;
  z-index: 90;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 1px 0 calc(1px + env(safe-area-inset-bottom));
  border-top: 1px solid #292929;
  background: #0d0d0d;
}

.ad-banner-inner {
  max-width: 100%;
  line-height: 0;
}

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  align-items: end;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 72%);
  backdrop-filter: blur(3px);
}

.modal-sheet {
  position: relative;
  display: flex;
  width: min(100%, 620px);
  min-width: 0;
  height: min(86dvh, 760px);
  max-height: min(86dvh, 760px);
  margin: 0 auto;
  padding: 12px 16px max(18px, env(safe-area-inset-bottom));
  flex-direction: column;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  background: #151515;
  box-shadow: 0 -18px 44px rgb(0 0 0 / 55%);
  overflow: hidden;
  animation: sheet-in .2s ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
}

.modal-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
}

.modal-header h2 {
  grid-column: 2;
  margin: 0;
  color: #eeeeee;
  font-size: 1.1rem;
  text-align: center;
}

#modal-close { grid-column: 3; }

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #c8c8c8;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.icon-button:active { background: #242424; }

.modal-back {
  grid-column: 1;
  grid-row: 1;
  color: var(--accent);
  font-size: 2.25rem;
}

.search-wrap {
  position: relative;
  margin-top: 8px;
}

.search-icon {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 14px;
  color: var(--muted);
  font-size: 1.35rem;
  transform: translateY(-52%);
  pointer-events: none;
}

#zone-search {
  width: 100%;
  min-height: 48px;
  padding: 9px 14px 9px 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  color: var(--ink);
  background: #0e0e0e;
  font-size: 16px;
}

#zone-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(255 152 0 / 11%);
}

.modal-guide {
  margin: 12px 4px 6px;
  color: var(--muted);
  font-size: .78rem;
}

.zone-list {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}

.zone-option {
  display: flex;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 54px;
  padding: 10px 8px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid #292929;
  background: #151515;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.zone-option:active { background: #222222; }
.option-main {
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone-option > .option-main { flex: 1 1 0; }

.option-primary {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: baseline;
  gap: 6px;
}

.option-offset {
  flex: 0 0 auto;
  color: #b2b2b2;
  font-size: .68rem;
  font-weight: 600;
  white-space: nowrap;
}

.option-sub {
  flex: 0 0 auto;
  max-width: 38%;
  overflow: hidden;
  color: var(--muted);
  font-size: .72rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chevron {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 1.35rem;
}

.empty-message {
  margin: 28px 0;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 200;
  right: 18px;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 18px;
  width: fit-content;
  max-width: min(540px, calc(100% - 36px));
  margin: auto;
  padding: 11px 16px;
  border: 1px solid #3a3a3a;
  border-radius: 10px;
  color: #f2f2f2;
  background: rgb(24 24 24 / 96%);
  box-shadow: var(--shadow);
  font-size: .83rem;
  text-align: center;
}

body.modal-open { overflow: hidden; }

body.dragging {
  overflow: hidden;
  cursor: grabbing;
  touch-action: none;
  user-select: none;
}

@media (max-width: 620px) {
  .modal-sheet {
    width: calc(100% - 16px);
    height: calc(100dvh - max(8px, env(safe-area-inset-top)));
    max-height: none;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-right: 13px;
    padding-left: 13px;
  }

  .time-card {
    height: 124px;
    min-height: 124px;
    max-height: 124px;
    padding-right: 12px;
    padding-left: 38px;
    grid-template-rows: 54px 45px;
  }

  .card-location {
    height: 54px;
    grid-template-rows: 27px 27px;
  }

  .zone-button { height: 27px; }

  .time-row,
  .picker-field {
    height: 45px;
    min-height: 45px;
  }

  .time-row {
    grid-template-columns: minmax(0, 1.18fr) minmax(96px, .82fr);
    gap: 7px;
  }

  .date-text { font-size: clamp(1.28rem, 6.3vw, 1.65rem); }
  .time-text { font-size: clamp(1.55rem, 7.5vw, 1.95rem); }
}

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