:root {
  color-scheme: light;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --fill: #f5f5f7;
  --blue: #0071e3;
  --blue-press: #0062c3;
  --danger: #d70015;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background: #fff;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

button { cursor: pointer; touch-action: manipulation; }

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -0.022em;
}

.noscript { padding: 24px 20px; }

.narrow { width: min(420px, 100%); }

#gate,
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

#gate {
  align-items: center;
  padding: 40px 20px 0;
}

.lead {
  margin: 8px 0 4px;
  color: var(--muted);
}

.lbl {
  display: block;
  margin: 22px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

input[type="text"],
select {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background-color: var(--fill);
  color: var(--text);
  font-size: 17px;
  -webkit-appearance: none;
  appearance: none;
}

select {
  padding-right: 40px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%236e6e73' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 14px;
}

input[type="text"]:focus,
select:focus {
  background-color: #fff;
  border-color: var(--blue);
}

input::placeholder { color: #86868b; }

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.primary:active { background: var(--blue-press); }

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

#join .primary {
  width: 100%;
  margin-top: 22px;
}

.primary.is-busy,
button:disabled {
  opacity: 0.55;
  pointer-events: none;
}

.error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 15px;
}

.crest {
  display: block;
  width: 44px;
  height: auto;
  flex: none;
}

.crest-login {
  width: 96px;
  margin: 0 auto 16px;
}

#gate h1 { text-align: center; }

.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.brand > div { min-width: 0; }

.brand h1 { font-size: 22px; }

.site-footer {
  margin-top: auto;
  padding: 28px 20px calc(16px + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.wide {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 28px 20px 24px;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.who {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.quiet {
  flex: none;
  margin-top: 4px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--fill);
  color: var(--text);
  font-size: 15px;
}

.toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  margin-bottom: 8px;
}

.toolbar .primary { width: 100%; }

.status {
  min-height: 22px;
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 15px;
}

.status.is-error { color: var(--danger); }

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

.frame { position: relative; }

.open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
}

.open img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  background: var(--fill);
}

.del {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

.cap { margin: 8px 2px 0; }

.cap strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.cap span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.empty {
  margin: 8px 0;
  color: var(--muted);
  grid-column: 1 / -1;
}

#viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: #000;
  color: #fff;
}

.viewer-bar {
  display: flex;
  justify-content: space-between;
  padding: max(8px, env(safe-area-inset-top)) 8px 0;
}

.viewer-bar button {
  padding: 12px;
  border: 0;
  background: none;
  color: #fff;
  font-size: 17px;
}

#viewer-delete { color: #ff6961; }

#viewer img {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  object-fit: contain;
  background: #000;
}

#viewer-caption {
  margin: 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  font-size: 15px;
  text-align: center;
}

@media (min-width: 720px) {
  #gate { padding-top: 12vh; }

  .brand h1 { font-size: 32px; }

  .toolbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .toolbar .primary { width: auto; }

  .toolbar select { width: 320px; }

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  background: rgba(0, 0, 0, 0.45);
}

.modal-card {
  width: min(420px, 100%);
  padding: 22px 22px 18px;
  border-radius: 16px;
  background: #fff;
}

.modal-card h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

#upload-count {
  margin: 8px 0 0;
  font-size: 17px;
}

#upload-name,
#upload-phase {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar {
  height: 6px;
  margin: 16px 0 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e5ea;
}

.bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

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