:root {
  color-scheme: light;
  --bg: #f7f5f2;
  --surface: #ffffff;
  --ink: #1f2428;
  --muted: #697078;
  --line: #ded8cf;
  --accent: #1f7a6d;
  --accent-strong: #14584f;
  --danger: #b3261e;
  --shadow: 0 16px 40px rgba(29, 31, 34, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px 110px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.secondary-link {
  color: var(--accent-strong);
  text-decoration: none;
  white-space: nowrap;
  font-weight: 700;
}

.notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
}

.media-tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: #e2ddd5;
  overflow: hidden;
  cursor: pointer;
}

.media-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-tile .tile-state,
.media-tile .play-mark {
  position: absolute;
  inset: auto 8px 8px auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

.media-tile .play-mark {
  inset: 50% auto auto 50%;
  width: 48px;
  height: 48px;
  transform: translate(-50%, -50%);
  font-size: 1.2rem;
}

.placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--muted);
  font-size: 0.82rem;
}

.sentinel {
  height: 80px;
}

.empty-state {
  min-height: 55vh;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  margin: 14px 0 4px;
  font-size: 1.05rem;
  color: var(--ink);
}

.empty-state p {
  margin: 0;
}

.empty-mark {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: linear-gradient(135deg, #dfeeea, #f7efe5);
}

.fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 2rem;
  line-height: 1;
  box-shadow: var(--shadow);
}

.modal-backdrop,
.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(18, 20, 22, 0.72);
}

.modal-backdrop {
  display: grid;
  place-items: center;
  padding: 20px;
}

.dialog {
  width: min(100%, 380px);
  padding: 22px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 1.18rem;
}

.dialog p {
  margin: 0 0 18px;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  font-size: 0.86rem;
  color: var(--muted);
}

.field input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  margin-top: 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.primary-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.form-error {
  min-height: 20px;
  margin-top: 10px;
  color: var(--danger);
}

.viewer {
  display: grid;
  grid-template-rows: 56px 1fr;
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: env(safe-area-inset-top) 12px 0;
}

.icon-button,
.viewer-nav {
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.6rem;
}

.viewer-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 10px 12px 28px;
}

.viewer-stage img,
.viewer-stage iframe {
  max-width: 100%;
  max-height: 100%;
  border: 0;
  background: #000;
}

.viewer-stage iframe {
  width: min(100%, 960px);
  aspect-ratio: 16 / 9;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  width: 42px;
  height: 58px;
  transform: translateY(-50%);
  border-radius: 8px;
  font-size: 2.4rem;
}

.viewer-nav.prev {
  left: 8px;
}

.viewer-nav.next {
  right: 8px;
}

.upload-shell {
  max-width: 760px;
}

.upload-panel {
  display: grid;
  gap: 14px;
}

.file-drop {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 220px;
  border: 2px dashed #b9c6c1;
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
  cursor: pointer;
}

.file-drop input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.file-drop-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #e0f1ed;
  color: var(--accent-strong);
  font-size: 2rem;
}

.file-drop small {
  color: var(--muted);
}

.selected-list {
  display: grid;
  gap: 8px;
}

.selected-item,
.progress-panel li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.selected-item span,
.progress-panel small {
  color: var(--muted);
  font-size: 0.82rem;
}

.progress-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.progress-panel > button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  min-height: 50px;
  border: 0;
  background: transparent;
  padding: 0 16px;
  font-weight: 800;
}

.progress-body {
  padding: 0 14px 14px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: #e3e0db;
  overflow: hidden;
}

#progress-bar {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.progress-panel ol {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
  padding: 12px 0 0;
  margin: 0;
  list-style: none;
}

@media (min-width: 720px) {
  .media-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .topbar h1 {
    font-size: 1.75rem;
  }
}
