:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #656b73;
  --line: #d9dde3;
  --soft: #f6f7f8;
  --paper: #ffffff;
  --accent: #0b7f88;
  --accent-ink: #064e55;
  --warm: #f3b94e;
  --danger: #b52c2c;
  --shadow: 0 10px 28px rgba(24, 33, 42, 0.08);
  font-family:
    "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #eef1f4;
  color: var(--ink);
}

body {
  font-size: 15px;
  line-height: 1.65;
}

button,
input,
select {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.header-note,
.privacy-note,
.drop-zone small {
  color: var(--muted);
  font-size: 12px;
}

.header-note {
  padding: 5px 9px;
  border: 1px solid #b8dfe2;
  border-radius: 999px;
  background: #edfafa;
  color: var(--accent-ink);
  white-space: nowrap;
}

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 24px;
  margin-bottom: 22px;
  padding: 26px 0 12px;
}

.eyebrow,
.step-label {
  margin: 0 0 4px;
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.hero h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 40px);
  line-height: 1.18;
}

.lead {
  max-width: 760px;
  margin: 12px 0 0;
  color: #3a4047;
}

.hero-notes {
  display: grid;
  gap: 4px;
  max-width: 800px;
  margin: 14px 0 0;
  padding-left: 1.2em;
  color: #4d5660;
  font-size: 13px;
}

.hero-meter {
  display: flex;
  gap: 7px;
}

.hero-meter span {
  display: grid;
  min-width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 800;
}

.tool-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
}

.control-panel,
.viewer-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.control-panel {
  align-self: start;
  padding: 18px;
}

.control-panel h2,
.viewer-toolbar h2,
.gallery-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.drop-zone {
  display: grid;
  min-height: 174px;
  margin: 18px 0 12px;
  padding: 18px;
  place-items: center;
  border: 2px dashed #b8c3cc;
  border-radius: 8px;
  background: #fbfcfd;
  color: #2d3944;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    transform 0.16s ease;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-zone.is-dragover {
  border-color: var(--accent);
  background: #eefafa;
  transform: translateY(-1px);
}

.drop-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  font-weight: 300;
}

.status-box {
  display: grid;
  gap: 3px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid #d7e8ea;
  border-radius: 8px;
  background: #f3fbfc;
}

.safety-note,
.format-note {
  display: grid;
  gap: 4px;
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid #f0d28b;
  border-radius: 8px;
  background: #fff9e8;
  color: #594017;
  font-size: 13px;
}

.format-note {
  border-color: #b8dfe2;
  background: #f3fbfc;
  color: var(--accent-ink);
}

.sample-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

.sample-actions span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sample-button {
  min-height: 36px;
  border: 1px solid #b8dfe2;
  border-radius: 8px;
  background: #f3fbfc;
  color: var(--accent-ink);
  cursor: pointer;
  font-weight: 700;
}

.sample-button:hover {
  background: #e8f7f8;
}

.status-box span {
  color: var(--muted);
  font-size: 13px;
}

.status-box.is-error {
  border-color: #efbbbb;
  background: #fff4f4;
}

.status-box.is-error strong {
  color: var(--danger);
}

.options {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #39434d;
  cursor: pointer;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.viewer-panel {
  min-width: 0;
  overflow: hidden;
}

.viewer-toolbar,
.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 0 32px 0 10px;
}

.summary-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #f9fafb;
}

.summary-strip span,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #edf2f3;
  color: #39434d;
  font-size: 13px;
}

.message {
  margin: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
}

.message.is-error {
  border-color: #efbbbb;
  background: #fff4f4;
  color: var(--danger);
}

.message.is-warning {
  border-color: #f0d28b;
  background: #fff9e8;
  color: #705219;
}

.external-image-notice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin: 0 18px 18px;
  padding: 14px;
  border: 1px solid #f0d28b;
  border-radius: 8px;
  background: #fff9e8;
  color: #594017;
}

.external-image-notice p {
  margin: 4px 0 0;
  font-size: 13px;
}

.external-image-notice button {
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.external-image-notice button:disabled {
  background: #9fb6ba;
  cursor: default;
}

.external-image-notice.is-loaded {
  border-color: #b8dfe2;
  background: #f3fbfc;
  color: var(--accent-ink);
}

.sheet-viewport {
  max-height: 64vh;
  overflow: auto;
  background: #dfe4ea;
}

.sheet-canvas {
  position: relative;
  display: inline-block;
  transform-origin: top left;
}

.sheet-table {
  position: relative;
  overflow: visible;
  background: #fff;
}

.sheet-grid .col-head,
.sheet-grid .row-head,
.sheet-grid .grid-cell {
  position: absolute;
  box-sizing: border-box;
  min-width: 0;
  border: 0;
  padding: 0 2px;
  background: #fff;
  color: #222;
  font-size: 12px;
  line-height: 1.05;
  vertical-align: top;
}

.sheet-grid .col-head,
.sheet-grid .row-head {
  z-index: 3;
  border: 1px solid #d7dce1;
  background: #eef1f4;
  color: #5a626b;
  font-weight: 700;
  text-align: center;
}

.sheet-table .corner {
  z-index: 5;
}

.sheet-table .col-head {
  line-height: 22px;
}

.sheet-table .row-head {
  padding: 0 3px 0 0;
  line-height: 1;
}

.sheet-grid .grid-cell {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  border-left: 1px solid #d7dce1;
  border-top: 1px solid #d7dce1;
  background: transparent;
  overflow: visible;
  white-space: nowrap;
  word-break: normal;
}

.sheet-grid.no-gridlines .grid-cell {
  border-color: transparent;
}

.sheet-grid .grid-cell.has-image {
  background: #fffbec;
  outline: 2px solid rgba(243, 185, 78, 0.5);
  outline-offset: -2px;
}

.cell-text {
  position: relative;
  z-index: 1;
  display: inline-block;
  flex: 0 0 auto;
}

.grid-border-segment {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.sheet-grid .grid-cell.is-wrap-text {
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.sheet-grid .grid-cell.is-wrap-text .cell-text {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
}

.sheet-grid .grid-cell.is-shrink-text .cell-text {
  max-width: 100%;
}

.sheet-grid .grid-cell.is-vertical-text .cell-text {
  writing-mode: vertical-rl;
  text-orientation: upright;
  white-space: pre-wrap;
}

.cell-images {
  display: grid;
  gap: 4px;
  margin-top: 4px;
}

.cell-images img {
  display: block;
  max-width: 170px;
  max-height: 126px;
  border: 1px solid #cfd6dd;
  border-radius: 4px;
  background: #fff;
  cursor: zoom-in;
  object-fit: contain;
}

.external-image-placeholder {
  display: grid;
  min-width: 112px;
  min-height: 54px;
  max-width: 170px;
  max-height: 126px;
  place-items: center;
  padding: 8px;
  border: 1px dashed #d2b86d;
  border-radius: 4px;
  background: #fff9e8;
  color: #705219;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
}

.external-image-placeholder.is-gallery {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
}

.drawing-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.drawing-layer img {
  position: absolute;
  display: block;
  border: 1px solid rgba(80, 91, 105, 0.35);
  background: #fff;
  cursor: zoom-in;
  object-fit: fill;
  pointer-events: auto;
}

body:not(.fit-images) .cell-images img {
  width: auto !important;
  height: auto !important;
  max-width: none;
  max-height: none;
}

body:not(.highlight-images) .sheet-grid .grid-cell.has-image {
  background: #fff;
  outline: 0;
}

.image-gallery {
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.image-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 16px 18px 18px;
}

.image-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.image-card button {
  display: grid;
  aspect-ratio: 4 / 3;
  width: 100%;
  place-items: center;
  border: 1px solid #d7dce1;
  border-radius: 6px;
  background: #f7f8f9;
  cursor: zoom-in;
}

.image-card button.is-disabled-preview {
  cursor: default;
}

.image-card img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-card strong {
  font-size: 13px;
}

.image-card small {
  color: var(--muted);
  word-break: break-all;
}

.preview-dialog {
  width: min(900px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 18px;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.preview-dialog::backdrop {
  background: rgba(15, 23, 32, 0.58);
}

.dialog-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #eef1f4;
  color: #222;
  cursor: pointer;
}

#previewImage {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 18px auto 12px;
  object-fit: contain;
}

#previewMeta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  color: #39434d;
  font-size: 13px;
}

#previewMeta dt {
  font-weight: 700;
}

#previewMeta dd {
  margin: 0;
  word-break: break-all;
}

.license-note {
  display: grid;
  gap: 4px;
  max-width: 1240px;
  margin: 0 auto 32px;
  padding: 0 20px;
  color: var(--muted);
  font-size: 12px;
}

.related-panel,
.comment-panel {
  max-width: 1240px;
  margin: 20px auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.related-panel h2 {
  margin: 0 0 12px;
  font-size: 1.35rem;
}

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

.related-links a {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}

.related-links a:hover,
.related-links a:focus-visible {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.related-links span,
.comment-panel p {
  color: var(--muted);
}

.comment-panel p {
  margin-top: 0;
}

.excel-image-viewer-page .grid-container {
  max-width: 1240px;
}

@media (max-width: 860px) {
  .header-inner,
  .viewer-toolbar,
  .gallery-head,
  .hero,
  .tool-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .header-note,
  .toolbar-actions {
    justify-self: start;
  }

  .tool-grid {
    gap: 14px;
  }

  .external-image-notice {
    grid-template-columns: 1fr;
  }

  .external-image-notice button {
    width: 100%;
    white-space: normal;
  }

  .hero-meter {
    display: none;
  }

  .app-shell {
    padding: 18px 12px 36px;
  }

  .control-panel,
  .viewer-panel {
    border-radius: 8px;
  }

  .sheet-viewport {
    max-height: 62vh;
  }

  .related-panel,
  .comment-panel {
    margin: 16px 12px;
    padding: 16px;
  }

  .related-links {
    grid-template-columns: 1fr;
  }
}
