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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #111;
  color: #eee;
  min-height: 100vh;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Input */
#input-row {
  display: flex;
  gap: 8px;
}

#url-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #222;
  color: #eee;
  font-size: 15px;
  min-width: 0;
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  background: #e53e3e;
  color: white;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: #c53030; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

#status-msg {
  font-size: 13px;
  color: #aaa;
  margin-top: 6px;
  min-height: 18px;
}

/* Player — portrait */
#player-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#player-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

#player-wrapper > #youtube-player,
#player-wrapper iframe {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

#player-click-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: pointer;
  /* reserve space for custom seeker bar */
  bottom: 20px;
}

#seeker-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 20px;
  z-index: 2;
  cursor: pointer;
  touch-action: none; /* let pointermove fire without page scroll on mobile */
  user-select: none;
  transition: height 0.15s ease;
}

#seeker-track {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.25);
  transition: background 0.15s ease;
}

#seeker-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, #e53e3e, #fc8181);
  pointer-events: none;
}

#seeker-beep-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.seeker-beep-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  margin-left: -2px; /* center on the time position */
  background: #fbbf24;
  pointer-events: none;
}

@media (hover: hover) {
  #seeker-bar:hover {
    height: 24px;
  }
  #seeker-bar:hover #seeker-track {
    background: rgba(255, 255, 255, 0.4);
  }
}

#seeker-bar:active {
  height: 24px;
}
#seeker-bar:active #seeker-track {
  background: rgba(255, 255, 255, 0.4);
}

/* Landscape mobile: thinner bar */
@media (orientation: landscape) and (max-height: 500px) {
  #seeker-bar {
    height: 16px;
  }
  #seeker-bar:active {
    height: 20px;
  }
  #player-click-overlay {
    bottom: 16px;
  }
  .seeker-beep-marker {
    width: 3px;
    margin-left: -1.5px;
  }
}

#timer-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#timer-bar {
  flex: 1;
  height: 8px;
  background: #333;
  border-radius: 4px;
  overflow: hidden;
}

#countdown-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #e53e3e, #fc8181);
  transition: width 0.1s linear;
  border-radius: 4px;
}

#next-beep-label {
  font-size: 14px;
  color: #aaa;
  min-width: 32px;
  text-align: right;
}

/* History */
#history-section h2 {
  font-size: 14px;
  color: #777;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#history-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e1e1e;
  padding: 10px 14px;
  border-radius: 6px;
  gap: 8px;
}

#history-list .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

#history-list .history-actions {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

#history-list .share-tile-btn {
  padding: 5px 10px;
  font-size: 13px;
  background: #2d6a4f;
}

#history-list .delete-btn {
  padding: 5px 10px;
  font-size: 13px;
  background: #742a2a;
}

#history-list li:hover {
  background: #2a2a2a;
}

#history-list .empty {
  color: #555;
  font-size: 14px;
}

/* Timer Edit */
#timer-edit-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

#volume-controls {
  display: flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
}

#volume-controls button {
  padding: 8px 10px;
  font-size: 13px;
  background: #444;
}

#volume-label {
  font-size: 12px;
  color: #aaa;
  min-width: 36px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#add-current-btn {
  font-size: 13px;
  padding: 8px 12px;
  background: #276749;
}

#timer-count {
  font-size: 12px;
  color: #777;
}

#timer-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#timer-list li {
  display: flex;
  flex-direction: column;
  background: #1a1a1a;
  padding: 6px 10px;
  border-radius: 4px;
  gap: 6px;
}

#timer-list .timer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#timer-list .timer-time {
  cursor: pointer;
  font-size: 14px;
  font-family: monospace;
  color: #eee;
}

#timer-list .timer-time:hover {
  color: #fff;
  text-decoration: underline;
}

#timer-list .empty {
  color: #555;
  font-size: 13px;
  padding: 4px 0;
}

#timer-list .timer-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

#timer-list .offset-btn {
  padding: 4px 0;
  min-width: 36px;
  font-size: 12px;
  background: #2c4a7c;
  flex-shrink: 0;
  text-align: center;
}

#timer-list .delete-btn {
  padding: 4px 8px;
  font-size: 13px;
  background: #742a2a;
  flex-shrink: 0;
  margin-left: 8px;
}

#timer-list .extend-btn {
  padding: 4px 10px;
  font-size: 13px;
  background: #276749;
  color: #fff;
  flex-shrink: 0;
  min-width: 32px;
}

#timer-list li.expanded .extend-btn {
  background: #1f5236;
}

#timer-list .timer-extend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 4px 2px;
  border-top: 1px solid #2a2a2a;
}

#timer-list .timer-extend[hidden] {
  display: none;
}

#timer-list .extend-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

#timer-list .extend-label {
  font-size: 11px;
  color: #888;
  min-width: 28px;
}

#timer-list .extend-loop input {
  width: 56px;
  padding: 4px 6px;
  font-size: 12px;
  background: #222;
  color: #eee;
  border: 1px solid #444;
  border-radius: 4px;
}

#timer-list .extend-loop .loop-add-btn {
  padding: 4px 10px;
  font-size: 12px;
  background: #2c4a7c;
  color: #fff;
}

/* Flash overlay */
#flash-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

#flash-overlay.flash {
  animation: flash 0.25s ease-out forwards;
}

@keyframes flash {
  0%   { background: rgba(252, 129, 129, 0.45); }
  100% { background: transparent; }
}

/* Landscape mobile */
@media (orientation: landscape) and (max-height: 500px) {
  #player-section {
    display: grid;
    grid-template-columns: 1fr 180px;
    grid-template-rows: auto auto;
    column-gap: 12px;
    row-gap: 6px;
  }

  /* 左欄：影片 + 倒數條 + 播放按鈕 */
  #player-wrapper {
    grid-column: 1;
    grid-row: 1;
    padding-bottom: 0;
    height: 200px;
  }

  #timer-row {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
  }

  /* 右欄：通知點列表，跨滿三列 */
  #timer-edit {
    grid-column: 2;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  #timer-list {
    flex: 1;
    max-height: none;
    min-height: 0;
    overflow-y: auto;
  }

  #timer-list .extend-once .offset-btn {
    min-width: 30px;
    padding: 3px 0;
    font-size: 11px;
  }

  #timer-list .extend-loop input {
    width: 44px;
    font-size: 11px;
  }

  #timer-list .extend-loop .loop-add-btn {
    padding: 3px 6px;
    font-size: 11px;
  }

  #timer-list .extend-label {
    display: none;
  }
}
