:root {
  color-scheme: light only;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #61707c;
  --line: #d9e1dd;
  --teal: #0f766e;
  --teal-dark: #0b5c55;
  --gold: #d99b22;
  --rose: #c0564a;
  --shadow: 0 18px 40px rgba(23, 32, 42, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  letter-spacing: 0;
  forced-color-adjust: none;
  min-height: 100svh;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

.app-header h1 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.25;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.header-actions,
.project-actions,
.transport {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button {
  background: var(--teal);
  color: #fff;
  padding: 0 16px;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.ghost-button,
.small-button {
  background: #eef4f1;
  color: var(--teal-dark);
  border: 1px solid #cbdad4;
  padding: 0 13px;
}

.small-button {
  min-height: 32px;
  font-size: 13px;
}

.wide-button {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(330px, 1fr) minmax(280px, 350px);
  gap: 18px;
  padding: 18px;
  align-items: start;
}

.panel,
.preview-stage {
  min-width: 0;
}

.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 8px 26px rgba(23, 32, 42, 0.04);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.section-heading h2 {
  margin: 0 0 10px;
}

.compact-heading {
  margin-top: 12px;
}

.compact-heading h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: #33414d;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfdad5;
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

textarea {
  resize: vertical;
  min-height: 92px;
  line-height: 1.55;
}

input[type="range"] {
  padding: 0;
}

input[type="color"] {
  height: 42px;
  padding: 4px;
}

.field-row {
  display: grid;
  gap: 10px;
}

.field-row.two {
  grid-template-columns: 1fr 1fr;
}

.status-pill {
  border-radius: 999px;
  background: #eef4f1;
  color: var(--teal-dark);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.auth-panel strong {
  display: block;
  color: var(--teal-dark);
  font-size: 13px;
}

.auth-panel span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.auth-form input {
  width: 190px;
}

.hidden {
  display: none !important;
}

.project-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.project-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid #e2e8e5;
  border-radius: 8px;
  background: #fbfcfb;
}

.project-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
  text-align: left;
}

.project-number {
  display: inline-block;
  margin-right: 7px;
  color: var(--gold);
  font-weight: 900;
}

.project-name {
  vertical-align: middle;
}

.project-date {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.mini-button {
  min-height: 30px;
  padding: 0 9px;
  background: #eef4f1;
  color: var(--teal-dark);
  border: 1px solid #cbdad4;
  font-size: 12px;
}

.danger-button {
  color: #8a2c25;
  background: #f9ecea;
  border-color: #efc4be;
}

.upload-box {
  border: 1px dashed #aabbb4;
  border-radius: 8px;
  padding: 18px;
  text-align: center;
  background: #f8fbfa;
  cursor: pointer;
}

.upload-box span {
  color: var(--teal-dark);
}

.upload-box input {
  display: none;
}

.image-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.thumb {
  flex: 0 0 70px;
  height: 102px;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: #e7eeeb;
  padding: 0;
}

.thumb.active {
  border-color: var(--teal);
}

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

.preview-stage {
  display: grid;
  gap: 12px;
  justify-items: center;
}

.preview-shell {
  width: min(100%, 430px);
  aspect-ratio: 9 / 16;
  background: #101820;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(23, 32, 42, 0.2);
}

#previewCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.transport,
.project-actions {
  width: min(100%, 640px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.project-actions {
  justify-content: flex-end;
}

#timeSlider {
  flex: 1;
}

#timeOutput {
  min-width: 48px;
  text-align: right;
  color: var(--muted);
  font-weight: 800;
}

.muted-text {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.angle-history {
  margin: -2px 0 12px;
}

.angle-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 7px;
}

.angle-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.angle-tag {
  min-height: 30px;
  max-width: 100%;
  padding: 0 10px;
  background: #eef4f1;
  color: var(--teal-dark);
  border: 1px solid #cbdad4;
  border-radius: 999px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.checklist {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.checklist li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.checklist li.done {
  color: var(--teal-dark);
}

.check-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #aabbb4;
  background: transparent;
}

.done .check-dot {
  border-color: var(--teal);
  background: var(--teal);
}

.toggle-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
}

.toggle-row input {
  width: auto;
}

.caption-list {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
}

.caption-item {
  border: 1px solid #e2e8e5;
  border-radius: 8px;
  padding: 9px;
  background: #fbfcfb;
}

.caption-time {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
}

.caption-text {
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 13px;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(300px, 1fr) minmax(330px, 430px);
  }

  .settings-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }

  .settings-panel .section {
    margin-bottom: 0;
  }
}

@media (max-width: 760px) {
  button {
    min-height: 44px;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .app-header h1 {
    font-size: 18px;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    flex: 1;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 10px;
  }

  .auth-panel {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 10px;
  }

  .auth-form {
    display: grid;
    grid-template-columns: 1fr;
  }

  .auth-form input {
    width: 100%;
  }

  .preview-stage {
    gap: 8px;
  }

  .preview-shell {
    width: min(74vw, 300px);
  }

  .settings-panel {
    display: block;
  }

  .settings-panel .section {
    margin-bottom: 14px;
  }

  .field-row.two {
    grid-template-columns: 1fr;
  }

  .transport,
  .project-actions {
    flex-wrap: wrap;
    width: 100%;
    padding: 8px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  textarea {
    min-height: 128px;
  }

  .section {
    padding: 14px;
    margin-bottom: 12px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .small-button {
    min-height: 38px;
  }

  #downloadProjectBtn {
    flex: 1 1 100%;
  }

  #copyVrewScriptBtn {
    position: sticky;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 6;
    min-height: 52px;
    box-shadow: 0 12px 26px rgba(15, 118, 110, 0.22);
  }

  .project-item {
    grid-template-columns: 1fr 1fr;
  }

  .project-title {
    grid-column: 1 / -1;
    text-align: left;
  }

  .mini-button {
    min-height: 38px;
  }

  .upload-box {
    padding: 20px 14px;
  }
}

@media (max-width: 420px) {
  .preview-shell {
    width: min(78vw, 280px);
  }

  .transport {
    gap: 8px;
  }

  #timeOutput {
    min-width: 44px;
  }

  .app-header h1 {
    font-size: 17px;
  }
}
