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

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text: #333;
  --muted: #666;
  --muted-light: #bbb;
  --border: #ddd;
  --bg: #fff;
  --bg-subtle: #f8f9fa;
  --accent: #2196F3;
  --accent-dark: #1976D2;
  --col-location: #e8421a;
  --col-duration: #2563eb;
  --col-when: #7c3aed;
  --col-mood: #059669;
  --panel-w: 360px;
  --header-h: 52px;
  --regen-h: 52px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Form bar ───────────────────────────────────────────────────────── */

#form-bar {
  flex-shrink: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1.75rem 0.55rem;
  position: relative;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

#brand-logo {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity 0.15s;
}

#brand-logo:hover { opacity: 1; }

/* ── Hero ───────────────────────────────────────────────────────────── */

#hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}

.hero-inner {
  text-align: center;
  padding: 2rem;
}

.hero-inner h1 {
  font-size: 3.5rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--text);
}

.hero-inner p {
  color: var(--muted);
  margin-top: 0.75rem;
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.hero-links {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hero-links a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.hero-links a:hover { text-decoration: underline; }
.hero-sep { color: var(--muted-light); }
.hero-about { color: var(--muted); }

#hero-usage {
  margin-top: 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: -0.01em;
}
#hero-usage.usage-low {
  color: #c0392b;
  font-weight: 600;
}

/* ── Sentence-style form ─────────────────────────────────────────────── */

#plan-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-sentence {
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1;
  color: var(--text);
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  margin: 0;
  white-space: nowrap;
}

.input-sentence select,
.input-sentence input[type="text"] {
  font-size: inherit;
  font-family: inherit;
  font-weight: inherit;
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  outline: none;
  transition: border-color 0.2s ease;
  color: var(--text);
}

.input-sentence select {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  padding: 4px 22px 4px 4px;
  min-width: 90px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0 center;
  background-size: 0.9em;
}

.input-sentence input[type="text"] {
  width: 120px;
  padding: 4px 4px;
}

.input-sentence select:focus,
.input-sentence input[type="text"]:focus {
  outline: none;
}

/* Per-field identity colors */
#location-input { border-bottom-color: var(--col-location); }
#duration-sel   { border-bottom-color: var(--col-duration); color: var(--col-duration); }
#when-sel       { border-bottom-color: var(--col-when);     color: var(--col-when);     }
#mood-sel       { border-bottom-color: var(--col-mood);     color: var(--col-mood);     }

.input-sentence input[type="text"]::placeholder {
  color: var(--muted-light);
  font-weight: 400;
}

#submit-btn {
  background-color: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 22px;
  border-radius: 25px;
  font-size: 1.5rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#submit-btn:hover {
  background-color: var(--accent-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

#submit-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

#random-btn {
  position: absolute;
  top: 0.5rem;
  right: 1rem;
  background: none;
  border: none;
  padding: 4px 6px;
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s, transform 0.15s;
  line-height: 1;
}

#random-btn:hover { opacity: 1; transform: rotate(15deg) scale(1.15); }
#random-btn:disabled { opacity: 0.15; cursor: not-allowed; transform: none; }

/* ── Result layout ──────────────────────────────────────────────────── */

#result {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#map {
  flex: 1;
  min-width: 0;
}

#panel {
  width: var(--panel-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--bg);
  overflow: hidden;
}

/* ── Panel header ───────────────────────────────────────────────────── */

#panel-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}

#panel-logo {
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.04em;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#new-plan-btn,
#share-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 0.28rem 0.65rem;
  font-size: 0.75rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  letter-spacing: -0.01em;
  transition: border-color 0.15s;
}

#new-plan-btn:hover,
#share-btn:hover { border-color: var(--text); }

#share-btn.copied {
  border-color: #059669;
  color: #059669;
}

#usage-indicator {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: -0.01em;
  padding: 0.2rem 0.5rem;
}

#usage-indicator.usage-low {
  color: #c0392b;
  font-weight: 600;
}

#timeline-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Loading / error ────────────────────────────────────────────────── */

.tl-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.75rem;
  padding: 3rem 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.tl-state.error { color: #c0392b; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Timeline ───────────────────────────────────────────────────────── */

.trip-title {
  padding: 0.85rem 1rem 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.refine-hint {
  padding: 0.2rem 1rem 0.7rem;
  font-size: 0.7rem;
  color: var(--muted-light);
  letter-spacing: 0.01em;
}

.day-section { }

.day-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem 0.45rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
  border-bottom: 1px solid var(--border);
}

.day-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.day-label {
  font-size: 0.73rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ── Activity item ──────────────────────────────────────────────────── */

.activity {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: background 0.1s, opacity 0.2s;
  border-left: 3px solid transparent;
  user-select: none;
}

.activity:hover { background: var(--bg-subtle); }

.activity.discarded {
  opacity: 0.35;
}

.activity.discarded .act-name,
.activity.discarded .act-meta,
.activity.discarded .act-desc {
  text-decoration: line-through;
  text-decoration-color: var(--muted-light);
}

.act-icon {
  font-size: 0.9rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  margin-top: 2px;
  opacity: 0.75;
}

.activity.discarded .act-icon { opacity: 0.35; }

.act-body { flex: 1; min-width: 0; }

.act-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.act-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.1rem;
  letter-spacing: 0;
}

.act-desc {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.2rem;
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.act-note {
  font-size: 0.68rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.15rem;
  opacity: 0.8;
}

.act-discard {
  flex-shrink: 0;
  align-self: flex-start;
  opacity: 0;
  font-size: 0.75rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 1px 3px;
  margin-top: 1px;
  line-height: 1;
  transition: opacity 0.12s, transform 0.1s;
  pointer-events: none;
}

.activity:hover .act-discard {
  opacity: 0.45;
  pointer-events: auto;
}

.activity:hover .act-discard:hover {
  opacity: 1;
  transform: scale(1.2);
}

.activity.discarded .act-discard {
  opacity: 1 !important;
  pointer-events: auto;
  filter: grayscale(1);
}

@media (max-width: 680px) {
  .act-discard { opacity: 0.35; pointer-events: auto; }
}

.act-wiki {
  flex-shrink: 0;
  align-self: flex-start;
  opacity: 0;
  font-size: 0.62rem;
  font-family: var(--font);
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  margin-top: 2px;
  white-space: nowrap;
  transition: opacity 0.12s, color 0.12s, border-color 0.12s;
  pointer-events: none;
}

.activity:hover .act-wiki {
  opacity: 1;
  pointer-events: auto;
}

.act-wiki:hover {
  color: #1565c0;
  border-color: #1565c0;
}

.activity.discarded .act-wiki {
  pointer-events: none;
  opacity: 0 !important;
}

/* ── Regen bar ──────────────────────────────────────────────────────── */

#regen-bar {
  flex-shrink: 0;
  height: var(--regen-h);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--bg);
}

#excl-label {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: -0.01em;
}

#regen-btn {
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  padding: 0.38rem 0.8rem;
  font-size: 0.8rem;
  font-family: var(--font);
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: opacity 0.15s;
}

#regen-btn:hover { opacity: 0.75; }
#regen-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Map markers ────────────────────────────────────────────────────── */

.map-marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font);
  color: #fff;
  border: 2.5px solid rgba(255,255,255,0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.22);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  user-select: none;
}

.map-marker:hover,
.map-marker.active {
  transform: scale(1.3);
  box-shadow: 0 4px 14px rgba(0,0,0,0.28);
  z-index: 10 !important;
}

.map-marker.discarded {
  filter: grayscale(1);
  opacity: 0.3;
  pointer-events: none;
}

.maplibregl-popup-content {
  padding: 9px 12px;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 0.8rem;
  max-width: 210px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.popup-name {
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

.popup-meta {
  color: var(--muted);
  font-size: 0.7rem;
}

/* ── Mobile ─────────────────────────────────────────────────────────── */

@media (max-width: 680px) {
  #form-bar { padding: 0.6rem 1rem 0.5rem; }

  .input-sentence {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.5rem;
    font-size: 1rem;
    line-height: 2.2;
    white-space: normal;
  }

  .input-sentence select {
    min-width: 0;
    padding: 2px 20px 2px 2px;
    font-size: 1rem;
    background-size: 0.8em;
  }

  .input-sentence input[type="text"] {
    width: 100px;
    padding: 2px 2px;
    font-size: 1rem;
  }

  #submit-btn {
    padding: 6px 18px;
    font-size: 1rem;
  }

  /* Result: map fills screen, panel is bottom sheet */
  #result {
    flex-direction: column;
    position: relative;
    overflow: hidden;
  }

  #map {
    position: absolute;
    inset: 0;
    height: 100% !important;
    flex: none;
    z-index: 1;
  }

  #panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 80vh;
    z-index: 100;
    border-left: none;
    border-top: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 24px rgba(0,0,0,0.1);
    /* Peek state: only header visible */
    transform: translateY(calc(100% - var(--header-h) - 20px));
    transition: transform 0.28s cubic-bezier(0.32, 0, 0.17, 1);
    will-change: transform;
  }

  #panel.sheet-open {
    transform: translateY(0);
  }

  /* Drag handle above header */
  #panel-header {
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    cursor: pointer;
    flex-direction: column;
    height: auto;
    padding: 8px 1rem 0.65rem;
    align-items: stretch;
    gap: 0;
  }

  /* Pull handle indicator */
  #panel-header::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 10px;
    flex-shrink: 0;
  }

  .header-inner-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  #timeline-wrap {
    height: calc(80vh - var(--header-h) - 20px - 36px);
    overflow-y: auto;
  }
}
