*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --green-dark: #1a3a0e;
  --green-mid: #2d5a1b;
  --green-bright: #4a9e4a;
  --pink: #d46fa0;
  --text: #f0f0e8;
  --text-dim: #a0b090;
  --surface: rgba(20, 40, 10, 0.92);
  --surface-light: rgba(40, 70, 20, 0.95);
  --marker-green: #4cde4c;
  --marker-yellow: #f0d040;
  --marker-orange: #f08030;
  --marker-red: #e83030;
  --marker-grey: #888880;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.5);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--green-dark);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ── Empty State ── */
#empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.empty-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.empty-icon {
  font-size: 72px;
  line-height: 1;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4));
}

.empty-content h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.empty-content p {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  max-width: 260px;
}

.empty-content strong {
  color: var(--text);
  font-weight: 700;
}

/* ── iOS Guide ── */
.ios-guide {
  margin-top: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 16px 18px;
  text-align: left;
  width: 100%;
  max-width: 300px;
}

.ios-guide-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.ios-guide-steps {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ios-guide-steps li {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}

.ios-share-icon {
  display: inline-block;
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  color: var(--text);
}

.ios-guide-note {
  margin-top: 10px !important;
  font-size: 12px !important;
  color: rgba(160,176,144,0.7) !important;
  max-width: none !important;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 8px;
}

/* ── Buttons ── */
.btn-primary {
  background: var(--green-bright);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(74,158,74,0.4);
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 1px 6px rgba(74,158,74,0.3);
}

.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  border: 1.5px solid rgba(160,176,144,0.4);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 15px;
  cursor: pointer;
}

.btn-danger {
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ── Map View ── */
#map-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  gap: 8px;
  z-index: 10;
}

.toolbar-btn {
  background: var(--surface-light);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.toolbar-btn:active { opacity: 0.75; }

/* Boss Key full-screen overlay */
#boss-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9999;
  cursor: pointer;
}

#boss-overlay.active {
  display: block;
}

/* ── Map Container ── */
#map-container {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #0a1a05;
}

/* Wrapper 高度由圖片撐開，markers-layer 的 height:100% 才能覆蓋完整圖片 */
#map-wrapper {
  position: relative;
  line-height: 0; /* 消除 img 下方多餘空隙 */
}

#map-image {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  -webkit-user-drag: none;
}

#markers-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ── Hint ── */
#hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px;
  background: var(--surface);
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ── Markers ── */
.marker {
  position: absolute;
  width: 34px;
  height: 34px;
  transform: translate(-50%, -50%); /* pie center = click point */
  cursor: pointer;
  z-index: 5;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* suppress iOS long-press callout */
}

.marker-bubble {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1.5px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 5px 9px;
  min-width: 70px;
  max-width: 130px;
  text-align: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  white-space: nowrap;
  pointer-events: none; /* bubble doesn't intercept clicks */
}

.marker-bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--surface);
  border-bottom: none;
}

.marker-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}

.marker-countdown {
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

/* ── Pie Chart ── */
.marker-pie {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.28);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  flex-shrink: 0;
  background: conic-gradient(
    from -90deg,
    var(--pie-color, #e03030) 0% var(--pie-pct, 100%),
    white var(--pie-pct, 100%) 100%
  );
}

/* Active countdown: red */
.marker.state-active .marker-countdown { color: #e84040; }
.marker.state-active .marker-bubble { border-color: rgba(232, 64, 64, 0.3); }

/* Grace period: green */
.marker.state-grace .marker-countdown { color: #3cc83c; }
.marker.state-grace .marker-bubble { border-color: rgba(60, 200, 60, 0.3); }

/* Truly expired */
.marker.state-expired .marker-countdown { color: #888; }
.marker.state-expired .marker-bubble { opacity: 0.55; }
.marker.state-expired .marker-title { color: var(--text-dim); }
.marker.state-expired .marker-pie {
  background: #888;
  border-color: rgba(0, 0, 0, 0.2);
}

/* Quick time buttons */
.quick-time-btns {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.quick-time-btn {
  flex: 1;
  background: rgba(74, 158, 74, 0.18);
  color: #7dda7d;
  border: 1.5px solid rgba(74, 158, 74, 0.35);
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
}

.quick-time-btn:active {
  background: rgba(74, 158, 74, 0.35);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.modal-sheet {
  background: #1e3d12;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 24px 20px 36px;
  width: 100%;
  max-width: 480px;
  border-top: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.modal-sheet h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 500;
}

.form-group input[type="text"] {
  width: 100%;
  background: rgba(0,0,0,0.3);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
  outline: none;
}

.form-group input[type="text"]:focus {
  border-color: var(--green-bright);
}

.time-inputs {
  display: flex;
  gap: 10px;
  align-items: center;
}

.time-field {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.time-field input[type="number"] {
  flex: 1;
  background: rgba(0,0,0,0.3);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 12px 8px;
  font-size: 20px;
  color: var(--text);
  text-align: center;
  outline: none;
  min-width: 0;
  -moz-appearance: textfield;
  appearance: textfield;
  font-weight: 600;
}

.time-field input[type="number"]::-webkit-inner-spin-button,
.time-field input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.time-field input[type="number"]:focus {
  border-color: var(--green-bright);
}

.time-field span {
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* Notify section */
.notify-section {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  overflow: hidden;
}

.notify-ios-hint {
  font-size: 12px;
  color: var(--text-dim);
  padding: 10px 14px;
  background: rgba(255,200,0,0.07);
  border-top: 1px solid rgba(255,255,255,0.06);
  line-height: 1.5;
}

/* Notify toggle row */
.notify-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.notify-toggle:last-of-type {
  border-bottom: none;
}

.notify-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.notify-toggle-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.notify-toggle-desc {
  font-size: 12px;
  color: var(--text-dim);
}

.toggle-switch {
  position: relative;
  flex-shrink: 0;
}

.toggle-switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  display: block;
  width: 50px;
  height: 28px;
  border-radius: 14px;
  background: rgba(255,255,255,0.15);
  position: relative;
  transition: background 0.2s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--green-bright);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(22px);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.modal-actions button {
  flex: 1;
  padding: 14px;
  font-size: 16px;
}

/* Small confirm modal */
#delete-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#delete-modal {
  background: #1e3d12;
  border-radius: 16px;
  padding: 24px 20px;
  width: 100%;
  max-width: 320px;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: var(--shadow);
  text-align: center;
}

#delete-modal h3 {
  font-size: 17px;
  margin-bottom: 8px;
}

#delete-modal p {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 20px;
}

#delete-modal .modal-actions {
  margin-top: 0;
}

/* Scrollbar for map container */
#map-container::-webkit-scrollbar { display: none; }
#map-container { scrollbar-width: none; }
