:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --line: #d7ded8;
  --line-strong: #a9b7ad;
  --text: #171b18;
  --muted: #66746b;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --danger: #a03434;
  --focus: #e4b44c;
  --shadow: 0 12px 36px rgba(32, 42, 35, 0.08);
  font-family: "Yu Gothic", "Meiryo", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px clamp(10px, 2vw, 24px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 80;
}

.app-header h1,
.panel-head h2,
.control-section h2 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: clamp(16px, 2.2vw, 22px);
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.app-title {
  min-width: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-wrap: wrap;
}

.icon-action,
.text-action {
  min-height: 30px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  line-height: 1.1;
  padding: 4px 5px;
}

.icon-action {
  min-width: 22px;
  font-size: 16px;
}

.text-action {
  font-size: 12px;
}

.history-action,
.sort-action {
  min-width: 18px;
  padding-inline: 3px;
}

.sort-action {
  font-size: 14px;
}

.selection-action {
  min-height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.selection-action-fill {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.selection-action-blank {
  background: #fff;
  color: var(--text);
}

.language-select {
  flex: 0 0 auto;
  width: auto;
  min-width: 54px;
  min-height: 30px;
  padding: 4px 22px 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background-color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.icon-action:hover {
  background: transparent;
  color: var(--accent-dark);
}

.text-action:hover,
.selection-action:hover {
  background: var(--surface-2);
}

.selection-action-fill:hover {
  background: #2b332d;
}

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

.menu-action {
  display: none;
  order: 999;
}

.app-shell {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 18px clamp(10px, 2.2vw, 28px) 34px;
}

.drop-zone {
  min-height: 112px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: 18px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 2px dashed var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
}

.drop-zone.is-dragover {
  border-color: var(--accent);
  background: #f2fbf7;
}

.drop-zone:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus), transparent 35%);
  outline-offset: 3px;
}

.drop-zone__mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 34px;
  font-weight: 700;
}

.drop-zone strong,
.drop-zone span {
  display: block;
}

.drop-zone span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.text-link {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 330px);
  gap: 16px;
  align-items: start;
}

.sheet-panel,
.control-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sheet-panel {
  min-width: 0;
  overflow: hidden;
}

.control-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
  position: sticky;
  top: 58px;
  max-height: calc(100vh - 70px);
  overflow-y: auto;
  align-self: start;
  padding-right: 2px;
}

.control-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-tab {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.1;
  padding: 7px 5px;
}

.control-tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.control-tab.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent-dark);
}

.control-pane {
  min-height: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.control-section h2 {
  font-size: 16px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.button-row,
.field-grid,
.list-actions {
  display: grid;
  gap: 6px;
}

.button-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.button-row-tight {
  display: flex;
  flex-wrap: wrap;
}

.field-grid {
  grid-template-columns: repeat(2, minmax(74px, 1fr));
}

.field-grid label {
  min-width: 0;
}

.output-header-fields input {
  font-weight: 700;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.check-row input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--accent);
}

.list-actions {
  grid-template-columns: 44px 44px minmax(0, 1fr);
  padding: 12px 12px 0;
}

.button {
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 9px;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

.button:active {
  transform: translateY(1px);
}

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

.button:focus-visible,
.icon-action:focus-visible,
.text-action:focus-visible,
.selection-action:focus-visible,
.control-tab:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.text-content:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus), transparent 35%);
  outline-offset: 2px;
}

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

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

.button-secondary {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text);
}

.button-secondary:hover,
.button-ghost:hover {
  border-color: var(--line-strong);
  background: #e7eee9;
}

.sort-arrow-button {
  min-height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.08);
}

.sort-arrow-button span {
  transform: translateY(-1px);
}

.sort-arrow-button:hover {
  border-color: rgba(15, 118, 110, 0.36);
  background: #eef8f4;
  color: var(--accent-dark);
}

.button-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.history-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.history-button:disabled {
  opacity: 0.36;
}

.clear-edits-button {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.button-danger {
  background: #fff2ef;
  color: var(--danger);
  border-color: #ecc9c2;
}

.button-danger:hover {
  background: #ffe6df;
}

.asset-grid {
  height: calc(100vh - 284px);
  min-height: 430px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-auto-rows: max-content;
  gap: 10px;
  align-items: start;
  align-content: start;
}

.asset-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-weight: 700;
  padding: 40px 12px;
}

.asset-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: clip;
}

.asset-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: transparent;
  transition: width 140ms ease, background-color 140ms ease;
  z-index: 8;
}

.asset-card[aria-current="true"] {
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(20, 83, 45, 0.08);
}

.asset-card[data-selected="true"] {
  background: #fff;
}

.asset-card[data-selected="true"] .asset-card__top {
  background: #fbfdfc;
}

.asset-card[data-selected="true"][aria-current="true"] {
  box-shadow: 0 8px 24px rgba(20, 83, 45, 0.1);
}

.asset-card[data-selected="true"]::before {
  width: 4px;
  background: rgba(15, 118, 110, 0.54);
}

.asset-card[data-selected="true"][aria-current="true"]::before {
  width: 5px;
  background: var(--accent);
}

.asset-card.is-dragging {
  opacity: 0.52;
}

.asset-card__top {
  display: grid;
  grid-template-columns: 18px 20px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  min-height: 40px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
}

.asset-drag-handle {
  width: 18px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  cursor: grab;
  font-size: 20px;
  line-height: 1;
  user-select: none;
}

.asset-drag-handle:hover {
  background: var(--surface-2);
  color: var(--accent-dark);
}

.asset-drag-handle:active {
  cursor: grabbing;
}

.asset-card__top input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--accent);
}

.asset-title {
  min-width: 0;
}

.asset-title strong,
.asset-title span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.asset-title strong {
  font-size: 12px;
}

.asset-title span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.asset-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.asset-frame {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 160px;
  background:
    linear-gradient(45deg, #e6ebe7 25%, transparent 25%),
    linear-gradient(-45deg, #e6ebe7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e6ebe7 75%),
    linear-gradient(-45deg, transparent 75%, #e6ebe7 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  overflow: hidden;
  touch-action: none;
}

.asset-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.asset-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.74);
  text-align: center;
  padding: 12px;
}

.caption-field {
  display: grid;
  gap: 5px;
  padding: 6px 8px 4px;
  border-top: 0;
  background: transparent;
}

.caption-field span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.caption-field textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid #e0e6df;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  resize: none;
  overflow: hidden;
  field-sizing: content;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.caption-field textarea::placeholder {
  color: #98a39b;
}

.crop-box {
  position: absolute;
  display: none;
  border: 2px solid #f8faf7;
  box-shadow: 0 0 0 9999px rgba(16, 18, 16, 0.28), inset 0 0 0 1px rgba(15, 118, 110, 0.9);
  cursor: move;
  touch-action: none;
  z-index: 4;
}

.asset-card[aria-current="true"] .crop-box {
  display: block;
}

.crop-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: #fff;
}

.crop-handle-nw {
  left: -9px;
  top: -9px;
  cursor: nwse-resize;
}

.crop-handle-ne {
  right: -9px;
  top: -9px;
  cursor: nesw-resize;
}

.crop-handle-sw {
  left: -9px;
  bottom: -9px;
  cursor: nesw-resize;
}

.crop-handle-se {
  right: -9px;
  bottom: -9px;
  cursor: nwse-resize;
}

.text-box {
  position: absolute;
  min-width: 44px;
  max-width: 92%;
  z-index: 5;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 20px;
  align-items: start;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.28);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.16);
}

.text-box.is-active {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus), transparent 48%);
}

.text-move {
  width: 20px;
  min-height: 24px;
  display: grid;
  place-items: center;
  color: rgba(23, 27, 24, 0.72);
  background: rgba(255, 255, 255, 0.72);
  border-right: 1px solid rgba(23, 27, 24, 0.12);
  cursor: grab;
  user-select: none;
  font-size: 12px;
}

.text-content {
  min-width: 36px;
  min-height: 24px;
  padding: 2px 5px;
  color: var(--text);
  font-weight: 800;
  line-height: 1.18;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 3px rgba(255, 255, 255, 0.9), 0 -1px 3px rgba(255, 255, 255, 0.9);
}

.text-delete {
  width: 20px;
  min-height: 24px;
  border: 0;
  border-left: 1px solid rgba(23, 27, 24, 0.12);
  background: rgba(255, 255, 255, 0.72);
  color: var(--danger);
  font-size: 13px;
  font-weight: 900;
  padding: 0;
}

.text-resize {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.22);
  cursor: nwse-resize;
  touch-action: none;
}

.asset-card__bottom {
  display: grid;
  gap: 7px;
  padding: 7px 8px 9px;
  border-top: 1px solid var(--line);
}

.asset-meta {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.asset-tools {
  display: grid;
  grid-template-columns: repeat(3, 28px) repeat(2, minmax(32px, 1fr));
  gap: 3px;
  align-items: center;
}

.mini-button {
  min-height: 27px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 9.5px;
  font-weight: 700;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.round-tool {
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px solid rgba(15, 118, 110, 0.34);
  border-radius: 50%;
  background: #fff;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.round-tool:hover,
.mini-button:hover {
  border-color: var(--accent);
  background: #eef8f4;
}

.card-adjustments {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.card-adjustments .range-row {
  font-size: 11px;
}

.video-slider {
  display: grid;
  gap: 4px;
}

.video-slider input {
  min-height: 28px;
  padding: 0;
  accent-color: var(--accent);
}

.control-section {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.share-section {
  gap: 10px;
}

.share-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.expires-text {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.share-code-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.share-code-panel input,
#openShareCodeInput,
#openVerifyCodeInput {
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 8px;
  min-height: 32px;
}

select.language-select {
  width: auto;
  min-height: 30px;
}

.field-grid input[type="number"] {
  min-width: 0;
}

textarea {
  resize: vertical;
}

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

.video-controls {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.video-controls input {
  padding: 0;
  accent-color: var(--accent);
}

.adjust-controls {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.range-row {
  gap: 7px;
}

.range-row span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.range-row output {
  color: var(--accent-dark);
  font-weight: 800;
}

.range-row input {
  min-height: 28px;
  padding: 0;
  accent-color: var(--accent);
}

.pdf-summary,
.status-text {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.preview-box {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fff;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.preview-head .button {
  min-height: 32px;
  padding: 6px 10px;
}

#previewCanvas {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}

progress {
  width: 100%;
  height: 12px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}

progress::-webkit-progress-bar {
  background: var(--surface-2);
}

progress::-webkit-progress-value {
  background: var(--accent);
}

progress::-moz-progress-bar {
  background: var(--accent);
}

.is-hidden {
  display: none !important;
}

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

  .control-panel {
    position: fixed;
    top: 50px;
    right: 0;
    bottom: 0;
    width: min(360px, 92vw);
    max-height: none;
    overflow-y: auto;
    padding: 10px;
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: -18px 0 40px rgba(32, 42, 35, 0.18);
    transform: translateX(104%);
    transition: transform 180ms ease;
    z-index: 70;
  }

  .control-tabs {
    position: static;
  }

  body.menu-open .control-panel {
    transform: translateX(0);
  }

  .menu-action {
    display: inline-grid;
    place-items: center;
    position: sticky;
    right: 0;
    background: var(--surface);
    box-shadow: -8px 0 12px rgba(255, 255, 255, 0.9);
  }

  .asset-grid {
    height: 64vh;
    grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  }
}

@media (max-width: 820px) {
  .app-header {
    align-items: center;
    position: sticky;
    padding: 6px 8px;
  }

  .app-title h1 {
    font-size: 15px;
  }

  .eyebrow {
    display: none;
  }

  .top-actions {
    flex-wrap: nowrap;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .top-actions::-webkit-scrollbar {
    display: none;
  }

  .icon-action,
  .text-action,
  .selection-action {
    flex: 0 0 auto;
    min-height: 30px;
    padding-inline: 5px;
  }

  .text-action {
    font-size: 11px;
  }

  .icon-action {
    min-width: 20px;
    font-size: 15px;
  }

  .history-action,
  .sort-action {
    min-width: 16px;
    padding-inline: 2px;
  }

  .selection-action {
    font-size: 11px;
    border-radius: 6px;
  }

  .drop-zone {
    grid-template-columns: 44px minmax(0, 1fr);
  }

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

  .asset-grid {
    height: auto;
    min-height: 360px;
    max-height: none;
    grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
    gap: 14px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding-inline: 10px;
  }

  .app-title h1 {
    max-width: 8.5em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

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

  .button-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .asset-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 176px), 1fr));
    gap: 16px;
  }
}
