* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: white;
  color: black;
  font-family: sans-serif;
  line-height: 1.6;
}

header {
  padding: 20px 24px;
}

header > span {
  font-size: 32px;
  font-weight: bold;
}

.server-check {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

#connect-esp {
  padding: 4px 12px;
  border: 1px solid black;
  border-radius: 4px;
  background: white;
  color: black;
  font: inherit;
  cursor: pointer;
}

#connect-esp:disabled {
  cursor: wait;
}

nav {
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
  gap: 6px;
  overflow-x: auto;   /* 狭い画面ではタブを横にスクロール */
  scrollbar-width: none;   /* スクロールバーは見せない(タブの下の線の 1 px で縦のバーが出ていた。横にはスクロールできる) */
}

nav::-webkit-scrollbar {
  display: none;
}

nav button {
  position: relative;
  margin-bottom: -1px;
  flex-shrink: 0;
  min-width: 72px;
  padding: 10px 20px;
  white-space: nowrap;
  border: 1px solid black;
  border-radius: 12px 12px 0 0;
  background: white;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

nav button[aria-pressed="true"] {
  z-index: 1;
  border-bottom-color: white;
  font-weight: bold;
}

nav button:focus-visible {
  outline: 2px solid black;
  outline-offset: -5px;
}

main {
  margin: 0 24px 24px;
}

.panel {
  min-height: 360px;
  padding: 24px;
  border: 1px solid black;
}

.panel p {
  margin: 12px 0 0;
}

#connectwifi p {
  margin-top: 0;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: normal;
}

/* 3 つの段階(画像 → AI → プロッタ)。幅が足りなければ自動で折り返し、スマホでは縦に並ぶ */
.image-stages {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  align-items: start;
  gap: 24px;
  margin-top: 24px;
}

.image-upload,
.ai-result,
.plot-result {
  min-width: 0;
}

.upload-box,
.result-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  padding: 16px;
  width: 100%;
  min-width: 0;
  border: 1px dashed black;
}

.upload-box {
  cursor: pointer;
}

.upload-box > span,
.result-box > span {
  flex-shrink: 0;
}

.send-ai {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#image-input,
#send-to-ai,
#send-to-ai-scene,
#download-plot {
  display: block;
  margin-top: 12px;
  max-width: 100%;
  font: inherit;
}

#send-to-ai,
#send-to-ai-scene,
#download-plot {
  background: white;
  color: black;
  border: 1px solid black;
  border-radius: 4px;
  padding: 2px 8px;
}

#send-to-ai:disabled,
#send-to-ai-scene:disabled,
#download-plot:disabled {
  cursor: not-allowed;
}

.join-mm {
  display: block;
  margin: 8px 0;
}

#join-mm {
  width: 4em;
  font: inherit;
  padding: 2px 4px;
  border: 1px solid black;
  border-radius: 4px;
}

.send-plot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

#plot-name {
  flex: 1 1 8em;
  min-width: 0;
  font: inherit;
  padding: 2px 6px;
  border: 1px solid black;
  border-radius: 4px;
}

#plot-star,
#send-plot {
  font: inherit;
  background: white;
  color: black;
  border: 1px solid black;
  border-radius: 4px;
  padding: 2px 8px;
}

#plot-star[aria-pressed="true"] {
  color: #c79100;
  border-color: #c79100;
}

#send-plot:disabled {
  cursor: not-allowed;
}

.image-upload:focus-within .upload-box {
  outline: 2px solid black;
  outline-offset: 3px;
}

#image-preview,
#ai-preview,
#plot-preview {
  display: block;
  max-width: 100%;
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  height: 0;
  object-fit: contain;
}

#image-preview[hidden],
#ai-preview[hidden],
#plot-preview[hidden] {
  display: none;
}

@media (max-width: 480px) {
  header {
    padding: 16px 12px;
  }

  main {
    margin: 0 12px 12px;
  }

  nav button {
    min-width: 56px;
    padding: 10px 14px;
  }

  .panel {
    padding: 20px 16px;
  }
}

/* パンタグラフの文字(SVG)の欄 */
.text-plot {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid black;
}

.text-plot h2 {
  margin: 0;
  font-size: 18px;
}

.text-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

.text-tools button {
  background: white;
  color: black;
  border: 1px solid black;
  border-radius: 4px;
  padding: 2px 10px;
  font: inherit;
}

.text-tools button[aria-pressed="true"] {
  background: black;
  color: white;
}

#text-live-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 12px;
  font: inherit;
  font-size: 18px;
  padding: 6px;
}

#text-live-input[hidden] {
  display: none;
}

#text-size {
  width: 4em;
  font: inherit;
}

#text-svg {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
}

#text-preview {
  display: block;
  margin-top: 12px;
  max-width: 100%;
  height: auto;
  border: 1px solid black;
}

#text-send {
  background: white;
  color: black;
  border: 1px solid black;
  border-radius: 4px;
  padding: 2px 8px;
  font: inherit;
}

.text-credit {
  font-size: 12px;
  color: #666;
}

/* パンタグラフの補正の欄 */
.calibration {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid black;
}

.calibration h2 {
  margin: 0;
  font-size: 18px;
}

.cal-mode {
  margin: 12px 0;
  border: 1px solid black;
  border-radius: 4px;
}

.cal-mode label {
  display: block;
}

#cal-input,
#cal-send {
  display: block;
  margin-top: 12px;
  max-width: 100%;
  font: inherit;
}

#cal-send {
  background: white;
  color: black;
  border: 1px solid black;
  border-radius: 4px;
  padding: 2px 8px;
}

#cal-debug {
  display: block;
  margin-top: 12px;
  max-width: 100%;
  height: auto;
}

#cal-debug[hidden] {
  display: none;
}

#cal-log {
  margin-top: 12px;
  white-space: pre-wrap;
  font-size: 12px;
}
