:root {
  color-scheme: light;
  --surface: #fbfbfd;
  --border: #d2d6dc;
  --accent: #0066cc;
  --accent-strong: #004a99;
  --text-primary: #1f2933;
  --text-muted: #4b5563;
  --danger: #d64545;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  color: var(--text-primary);
  background: var(--surface);
}

.app-bar {
  padding: 1rem clamp(1rem, 4vw, 3rem);
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-bar h1 {
  margin: 0 0 0.3rem;
  font-size: 1.5rem;
}

.app-bar p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.2rem clamp(1rem, 4vw, 3rem) 2rem;
  align-items: stretch;
}

.controls {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  min-height: 0;
}

.controls-intro h2 {
  margin: 0;
  font-size: 1.25rem;
}

.controls-intro p {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
}

.controls label {
  font-weight: 600;
}

.controls input {
  font-size: 1.1rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.controls button {
  font-size: 1.05rem;
  padding: 0.9rem 1.4rem;
  border-radius: 14px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  touch-action: manipulation;
}

.controls button:active {
  background: var(--accent-strong);
}

.canvas-tools {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.canvas-tools button:nth-child(2) {
  background: #ff7a18;
}
.form-row {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-bottom: 0.5em;
}
.form-row input[type="text"] {
  flex: 1;
  min-width: 0;
}

.form-row-textarea {
  flex-direction: column;
  align-items: stretch;
}

.form-row textarea {
  width: 100%;
  font-size: 1.1rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-family: inherit;
  resize: vertical;
}
.stamp-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.stamp-panel select {
  font-size: 1rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.image-panel {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.image-panel input[type="file"] {
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: #f8fafc;
}

.image-helper {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.judgement-panel {
  margin-top: 0.75rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fdfdff;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.judgement-panel h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-muted);
}

.judgement-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.judgement-label {
  font-weight: 600;
  min-width: 4.5rem;
}

.judgement-buttons {
  display: flex;
  gap: 0.4rem;
  flex: 1;
}

.judgement-btn {
  flex: 1;
  border-radius: 999px;
  border: 1px solid transparent;
  background: #eef2ff;
  color: var(--accent-strong);
  font-size: 0.95rem;
  padding: 0.4rem 0.6rem;
  transition:
    background 0.2s ease,
    color 0.2s ease;
}

.judgement-btn.is-active {
  background: var(--accent);
  color: white;
}
.judgement-inline {
  display: flex;
  align-items: center;
  gap: 0.5em;
}
.ghost-button {
  border: 1px dashed var(--accent);
  background: transparent;
  color: var(--accent-strong);
}

#statusMessage {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.canvas-wrapper {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #f4f6fa;
  padding: 1rem;
  display: flex;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  touch-action: none;
}

.pdf-stage {
  position: relative;
  width: 100%;
  min-width: 600px;
  min-height: 80vh;
  background: #fefefe;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  justify-content: center;
  transform-origin: center center;
}

#pdfBaseCanvas,
#fabricCanvas {
  display: block;
}

#pdfBaseCanvas {
  width: 100%;
  height: auto;
  position: relative;
  z-index: 1;
}

#fabricCanvas {
  /* Fabric.jsが管理するので直接スタイルを当てない */
  touch-action: manipulation;
}
/* Fabric.js はcanvasをdiv.canvas-containerでラップするため、
   そのラッパーに対してpositionを設定する必要がある */
.canvas-container {
  position: absolute !important;
  inset: 0;
  z-index: 2;
  touch-action: none; /* ←ズーム誤動作防止 */
}
@media (min-width: 960px) {
  .workspace {
    flex-direction: row;
    gap: 2rem;
  }

  .controls {
    flex: 0 0 360px;
    position: sticky;
    top: 6rem;
    align-self: flex-start;
    max-height: calc(100vh - 7rem);
    overflow-y: auto;
  }

  .canvas-wrapper {
    flex: 1;
  }
}

/* モバイル: 入力カラム固定、PDFビューのみスクロール */
@media (max-width: 959px) {
  .workspace {
    flex-direction: column-reverse;
    gap: 0;
    padding-bottom: 0;
  }

  .controls {
    position: sticky;
    bottom: 0;
    z-index: 20;
    max-height: 45vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.1);
  }

  .canvas-wrapper {
    flex: 1;
    overflow-y: auto;
  }
}

.form-fields {
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.2rem 1.2rem 1.2rem;
  margin-bottom: 1.1rem;
  background: #f8fafd;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  overflow: hidden;
  min-width: 0;
}
.form-fields legend {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent-strong);
  margin-bottom: 0.5rem;
  padding: 0 0.5em;
}

.form-fields-group summary {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--accent-strong);
  cursor: pointer;
  padding: 0.2em 0.5em;
  margin-bottom: 0.3em;
  outline: none;
}
.form-fields-group[open] summary {
  border-bottom: 1px solid var(--border);
}
.form-fields {
  margin-top: 0;
}
