:root {
  color-scheme: dark;
  --bg: #121417;
  --surface: #1c2026;
  --text: #f4f1ea;
  --muted: #b7b1a6;
  --line: #343a42;
  --accent: #ffb703;
  --danger: #ffb4a2;
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
}

button, a {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}

.topbar h1, .topbar p {
  margin: 0;
}

.topbar h1 {
  font-size: 1.05rem;
  font-weight: 700;
}

.back {
  color: var(--accent);
  text-decoration: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-decoration: none;
}

.card img {
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: 10px;
  background: #000;
}

.card span {
  font-size: 0.92rem;
}

.empty, .missing {
  padding: 24px 16px;
  color: var(--muted);
}

.stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
}

.stage {
  position: relative;
  width: min(100%, calc((100dvh - 180px) * 9 / 16));
  aspect-ratio: 9 / 16;
  background: #000;
  border-radius: 18px;
  overflow: hidden;
}

.stage[data-orientation="landscape"] {
  width: min(100%, calc((100dvh - 180px) * 16 / 9));
  aspect-ratio: 16 / 9;
}

.shoot {
  --topbar-pad: 6px;
  --stage-inset-top: calc(32px + env(safe-area-inset-top));
  --stage-inset-bottom: calc(45px + env(safe-area-inset-bottom));
  position: relative;
  height: 100dvh;
  overflow: hidden;
}

.shoot.is-maximized {
  --stage-inset-top: env(safe-area-inset-top);
  --stage-inset-bottom: env(safe-area-inset-bottom);
}

.shoot .topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  padding: calc(var(--topbar-pad) + env(safe-area-inset-top)) 16px var(--topbar-pad);
  background: rgb(18 20 23 / 0.25);
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.85);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.shoot.is-maximized .topbar,
.shoot.is-maximized .topbar * {
  pointer-events: none;
}

.shoot.is-maximized .topbar {
  opacity: 0;
  transform: translateY(-12px);
}

.shoot .topbar h1 {
  font-size: 0.9rem;
  line-height: 1.2;
}

.shoot .stage-wrap {
  position: absolute;
  inset: var(--stage-inset-top) 0 var(--stage-inset-bottom);
  padding: 0;
  transition: inset 0.28s ease;
}

.shoot .stage {
  width: min(100%, calc((100dvh - var(--stage-inset-top) - var(--stage-inset-bottom)) * 9 / 16));
  border-radius: 0;
  transition: width 0.28s ease;
}

.shoot .stage[data-orientation="landscape"] {
  width: min(100%, calc((100dvh - var(--stage-inset-top) - var(--stage-inset-bottom)) * 16 / 9));
}

.shoot-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.shoot-bar .drawer,
.shoot-bar .controls,
.shoot-bar button {
  pointer-events: auto;
}

.shoot .controls {
  align-items: end;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: transparent;
}

.shoot .side-group {
  display: flex;
  gap: 4px;
  justify-self: start;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.shoot.is-maximized .side-group,
.shoot.is-maximized .side-group button {
  pointer-events: none;
}

.shoot.is-maximized .side-group {
  opacity: 0;
  transform: translateY(10px);
}

.shoot .side {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 44px;
  padding: 6px 8px;
  font-size: 0.65rem;
  line-height: 1;
}

.shoot .side svg {
  display: block;
  width: 20px;
  height: 20px;
}

.shoot .chrome-toggle {
  justify-self: end;
}

.shoot [data-orient][data-orientation="landscape"] svg {
  transform: rotate(90deg);
}

.drawer {
  max-height: 140px;
  transition: opacity 0.28s ease, transform 0.28s ease, max-height 0.28s ease, padding 0.28s ease;
}

.shoot.is-maximized .drawer,
.shoot.is-maximized .drawer button {
  pointer-events: none;
}

.shoot.is-maximized .drawer {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  transform: translateY(8px);
}

@media (prefers-reduced-motion: reduce) {
  .shoot .topbar,
  .shoot .drawer,
  .shoot .side-group,
  .shoot .stage-wrap,
  .shoot .stage {
    transition: none;
  }
}

.shoot:has(.file-panel:not([hidden])) .stage-wrap {
  z-index: 2;
}

.shoot:has(.file-panel:not([hidden])) .shoot-bar {
  z-index: 1;
}

.stage video, .stage img, .result-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.stage .overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

video.mirror { transform: scaleX(-1); }

.drawer {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 16px 0;
}

.file-choice {
  flex: 0 0 auto;
  width: 72px;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--surface);
}

.file-choice img {
  display: block;
  width: 100%;
  height: 64px;
  object-fit: contain;
  border-radius: 8px;
}

.file-choice span {
  display: block;
  margin-top: 4px;
  font-size: 0.7rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-choice[aria-pressed="true"] {
  border-color: var(--accent);
}

.controls, .actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}

.actions {
  grid-template-columns: 1fr;
}

.share-error {
  margin: calc(8px + env(safe-area-inset-top)) 16px 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #f1a899;
  background: #fddfdf;
  color: #5f3f3f;
  text-align: left;
}

.share-error summary {
  cursor: pointer;
  text-align: center;
  font-weight: 700;
}

.share-error pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  font: 0.82rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.share-error[hidden] {
  display: none;
}

.side, .text-button, .primary, .file-label {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 12px 14px;
  text-align: center;
}

.primary {
  background: var(--accent);
  color: #1c1400;
  border-color: transparent;
  font-weight: 700;
}

.shutter {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 4px solid var(--accent);
  background: #fff;
  justify-self: center;
}

.shutter:disabled {
  opacity: 0.4;
}

.file-panel[hidden] {
  display: none;
}

.file-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  padding: 24px;
  text-align: center;
  background: #000;
}

.file-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.file-label {
  color: var(--text);
}

.result-photo {
  width: min(100%, calc((100dvh - 220px) * 9 / 16));
  aspect-ratio: 9 / 16;
  object-fit: contain;
  background: #000;
  border-radius: 18px;
}

.result-photo[data-orientation="landscape"] {
  width: min(100%, calc((100dvh - 220px) * 16 / 9));
  aspect-ratio: 16 / 9;
}

.popup-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 55%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.popup {
  width: min(520px, 100%);
  background: var(--surface);
  border-radius: 20px 20px 16px 16px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.popup h2, .popup p {
  margin: 0;
}

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

.email-note {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff6d8;
  color: #5c4b16;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
}

textarea,
label.field input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #121417;
  color: var(--text);
  padding: 10px;
  font: inherit;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
}

.popup-actions {
  display: flex;
  gap: 8px;
}

.popup-actions button { flex: 1; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #3a1d1d;
  color: var(--danger);
  text-align: center;
}

.busy {
  opacity: 0.7;
}
