:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #68736d;
  --line: #d8ded9;
  --panel: #ffffff;
  --surface: #f4f7f5;
  --accent: #176b52;
  --accent-strong: #0f503d;
  --danger: #a03333;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--surface);
}

button,
input {
  font: inherit;
}

button,
a {
  touch-action: manipulation;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 0 14px;
  cursor: pointer;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-strong);
}

button.ghost {
  background: transparent;
}

button.danger {
  color: var(--danger);
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-height: 42px;
  padding: 8px 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.4rem, 3vw, 2rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.05rem;
}

.stack {
  display: grid;
  gap: 14px;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--danger);
  font-weight: 650;
}

.auth-page {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(100%, 380px);
  display: grid;
  gap: 22px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.manage-page {
  min-height: 100svh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(14px, 3vw, 30px);
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

.top-actions,
.button-row,
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-title {
  justify-content: space-between;
}

.manage-layout {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px clamp(14px, 3vw, 30px) 30px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.library-panel {
  grid-column: 2;
  grid-row: 1 / span 3;
}

.current-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.current-preview img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.empty {
  color: var(--muted);
  padding: 16px;
  text-align: center;
}

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

.facts div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-width: 0;
}

.facts dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.facts dd {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
}

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

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.photo-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  display: grid;
}

.photo-card figure {
  margin: 0;
  aspect-ratio: 4 / 3;
  background: #111;
}

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

.photo-card-body {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.photo-card-title {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.photo-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.select-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.select-row input {
  width: 18px;
  min-height: 18px;
}

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

.schedule-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.frame-page {
  background: #000;
  width: 100vw;
  height: 100svh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.frame-stage {
  width: 100vw;
  height: 100svh;
  display: grid;
  place-items: center;
  background: #000;
}

.frame-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

.frame-empty {
  color: #e8ece9;
  font-size: clamp(1.2rem, 4vw, 2.5rem);
}

.montage-grid {
  width: 100vw;
  height: 100svh;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 1fr;
  gap: 6px;
  padding: 6px;
  background: #000;
}

.montage-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  min-height: 0;
}

.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
}

.start-overlay.is-hidden {
  display: none;
}

.start-overlay button {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.94);
  font-size: 1.1rem;
  min-height: 54px;
  padding: 0 24px;
}

.frame-controls {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  opacity: 0.12;
  transition: opacity 160ms ease;
}

.frame-controls:hover,
.frame-controls:focus-within {
  opacity: 1;
}

.frame-controls button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 1.5rem;
  padding: 0;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .manage-layout {
    grid-template-columns: 1fr;
  }

  .library-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .facts,
  .control-grid {
    grid-template-columns: 1fr;
  }
}
