* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #e9ecef;
  color: #1f2933;
}
.page {
  max-width: 1180px;
  margin: 24px auto 40px;
  padding: 0 16px;
}
.header {
  background: #ffffff;
  border: 1px solid #d6dbe1;
  border-radius: 8px;
  padding: 18px 22px;
  margin-bottom: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  color: #1f2933;
}
.header-reset-btn {
  min-width: 160px;
}
.form-card {
  background: #ffffff;
  border: 1px solid #d6dbe1;
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.form-book {
  position: relative;
  perspective: 2200px;
}
.form-card-front {
  position: relative;
  z-index: 2;
  transform-origin: left center;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}
.form-card-underlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,251,0.98)),
    repeating-linear-gradient(
      180deg,
      transparent 0,
      transparent 34px,
      rgba(25, 135, 84, 0.08) 34px,
      rgba(25, 135, 84, 0.08) 35px
    );
  opacity: 0;
}
.blank-sheet-copy {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.blank-sheet-title {
  font-size: 24px;
  font-weight: 700;
  color: #bcc5cf;
}
.blank-sheet-lines {
  display: grid;
  gap: 18px;
}
.blank-sheet-lines span {
  display: block;
  height: 1px;
  background: rgba(25, 135, 84, 0.14);
}
.form-book.is-flipping .form-card-underlay,
.form-book.is-flip-complete .form-card-underlay {
  opacity: 1;
}
.form-book.is-flipping .form-card-front {
  animation: book-page-flip 0.95s cubic-bezier(0.24, 0.8, 0.2, 1) forwards;
}
.form-book.is-flip-complete .form-card-front {
  visibility: hidden;
}
.section {
  margin-bottom: 22px;
  border: 1px solid #d9dee5;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.hidden { display: none !important; }
.section.hidden { display: none; }
.section-title {
  background: #198754;
  color: #fff;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.section-title.is-clickable {
  cursor: pointer;
}
.section-title.is-clickable::after {
  content: "Hide";
  float: right;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.9;
}
.section.is-collapsed .section-title::after {
  content: "Show";
}
.section.is-collapsed .section-body {
  display: none;
}
.section-body { padding: 18px; }
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 18px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field.full { grid-column: 1 / -1; }
label {
  font-size: 14px;
  font-weight: 700;
  color: #2f3a45;
}
.required-label::after {
  content: " *";
  color: #dc3545;
}
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #bcc5cf;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  color: #1f2933;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #198754;
  box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.14);
}
.field-error {
  border-color: #dc3545 !important;
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.14) !important;
}
textarea {
  min-height: 96px;
  resize: vertical;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 18px;
}
.photo-field {
  padding: 14px;
  border: 1px solid #d9dee5;
  border-radius: 8px;
  background: #f8fafb;
}
.photo-field button {
  min-width: 0;
}
.photo-status {
  font-size: 12px;
  color: #5c6773;
  min-height: 18px;
}
.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 26px;
}
button {
  min-width: 180px;
  min-height: 44px;
  padding: 11px 18px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  background: #198754;
  color: #fff;
  transition: background-color 0.15s ease, transform 0.05s ease;
}
button:hover { background: #157347; }
button:active { transform: translateY(1px); }
button.secondary { background: #6c757d; }
button.secondary:hover { background: #5c636a; }
.output {
  margin-top: 22px;
  padding: 16px;
  background: #f8fafb;
  border: 1px solid #d6dbe1;
  border-radius: 6px;
  white-space: pre-wrap;
  display: none;
  font-size: 13px;
}
.output.is-hidden {
  display: none !important;
}
.space-visual-wrapper {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}
.space-visual-meta {
  font-size: 13px;
  color: #5c6773;
}
.space-canvas-shell {
  width: 100%;
  overflow: auto;
  padding: 10px;
  border: 1px dashed #bcc5cf;
  border-radius: 6px;
  background: #f8fafb;
}
.space-canvas {
  position: relative;
  width: 320px;
  height: 220px;
  background: linear-gradient(180deg, #fff, #f4f6f8);
  border: 2px solid #adb5bd;
  border-radius: 10px;
  transform-origin: top left;
}
.draggable-square {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: none;
  cursor: grab;
}
.item-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: #000;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.14);
  padding: 4px;
  pointer-events: none;
}
.draggable-square:active { cursor: grabbing; }
.board { background: #dc3545; }
.tv { background: #0d6efd; }
.tablet { background: #6f42c1; }
.socket {
  background: #198754;
  font-size: 11px;
  line-height: 1.1;
  padding: 4px;
}
.snap-dartboard-btn {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  appearance: none;
  -webkit-appearance: none;
  max-width: calc(100% - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(0, 0, 0, 0.28);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.96);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  z-index: 2;
  touch-action: manipulation;
}
.snap-dartboard-btn:hover {
  background: #fff;
}
.snap-dartboard-btn:active,
.snap-dartboard-btn:focus {
  transform: translateX(-50%);
  outline: none;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  font-size: 13px;
  color: #425466;
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.legend i {
  width: 12px;
  height: 12px;
  display: inline-block;
  border-radius: 3px;
}
.preview-image {
  max-width: 100%;
  border: 1px solid #d6dbe1;
  border-radius: 6px;
  display: none;
  margin-top: 12px;
}
@media (max-width: 860px) {
  .header-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .grid, .photo-grid { grid-template-columns: 1fr; }
  button { width: 100%; }
}

@keyframes book-page-flip {
  0% {
    transform: rotateY(0deg);
    opacity: 1;
  }
  45% {
    transform: rotateY(-22deg);
    opacity: 1;
  }
  100% {
    transform: rotateY(-104deg);
    opacity: 0.08;
  }
}
