:root {
  color-scheme: light;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  color: #3e2f23;
  background: #fefefb;
}

* { box-sizing: border-box; }

body { margin: 0; background: #fefefb; }

button, input, select { font: inherit; }

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.topbar, .control-panel, .sequence-guide, .board, .safety-note {
  border: 1px solid #efe7d9;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(62, 47, 35, .06);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
}

.eyebrow { margin: 0 0 4px; color: #9c5230; font-weight: 700; font-size: .86rem; }
h1 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.2rem); }
.status-text { margin: 8px 0 0; line-height: 1.6; }

.result-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 228px;
}

.result-panel span {
  display: grid;
  gap: 2px;
  min-width: 106px;
  padding: 10px 13px;
  border-radius: 12px;
  background: #f7f1e8;
  font-size: .88rem;
}

.result-panel strong { font-size: 1.18rem; color: #4a3728; }

.control-panel {
  display: grid;
  grid-template-columns: minmax(190px, .8fr) minmax(230px, 1fr) minmax(250px, 1.45fr) auto;
  align-items: end;
  gap: 16px;
  margin-top: 18px;
  padding: 18px 20px;
}

.field { display: grid; gap: 7px; min-width: 0; }
.field label, .guide-label { font-weight: 700; font-size: .93rem; }
.field select, .field input[type="text"] {
  width: 100%;
  min-height: 45px;
  border: 1px solid #cdbda9;
  border-radius: 10px;
  padding: 8px 11px;
  color: #3e2f23;
  background: #fffefb;
}

.field input:focus, .field select:focus, button:focus-visible, .target:focus-visible {
  outline: 3px solid #e4b26c;
  outline-offset: 2px;
}

.count-field label { display: flex; justify-content: space-between; gap: 12px; }
.count-field output { color: #9c5230; font-size: 1.1rem; }
.count-field input { width: 100%; accent-color: #257836; }
.field-note { margin: -2px 0 0; font-size: .78rem; color: #6f6258; }
.is-hidden { display: none !important; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-button {
  min-height: 45px;
  border: 1px solid #bba994;
  border-radius: 10px;
  padding: 9px 13px;
  color: #4a3728;
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}
.tool-button.primary { border-color: #257836; color: #fff; background: #257836; }
.tool-button:hover { background: #f7f1e8; }
.tool-button.primary:hover { background: #1d5e2a; }

.validation-message {
  min-height: 1.4em;
  margin: 10px 4px 0;
  color: #a13b2c;
  font-weight: 700;
}

.sequence-guide {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-top: 4px;
  padding: 12px 16px;
  overflow-wrap: anywhere;
}
.sequence-guide strong { color: #4a3728; line-height: 1.55; }

.board {
  position: relative;
  width: 100%;
  height: min(62vw, 650px);
  min-height: 360px;
  margin-top: 16px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.line-layer, .targets-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.line-layer { pointer-events: none; }
.targets-layer { z-index: 1; }

.line-segment, .line-preview {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.line-segment { stroke: #257836; stroke-width: 11; }
.line-preview { stroke: #9c5230; stroke-width: 7; stroke-dasharray: 10 12; opacity: .72; }

.target {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: clamp(48px, 7vw, 76px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 4px solid #6f6258;
  border-radius: 50%;
  padding: 3px;
  color: #3e2f23;
  background: #fffefb;
  box-shadow: 0 3px 8px rgba(62, 47, 35, .17);
  cursor: pointer;
  font-size: clamp(1.15rem, 3.2vw, 2rem);
  font-weight: 800;
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body.linest-themed .target {
  min-height: 0;
  border-radius: 50%;
}

body.linest-themed .target:not(:disabled):active {
  transform: translate(-50%, -50%);
}

.board.is-dense .target {
  width: clamp(42px, 5.5vw, 58px);
  font-size: clamp(1rem, 2.4vw, 1.55rem);
}

.target.is-current { border-color: #9c5230; box-shadow: 0 0 0 5px rgba(156, 82, 48, .2); }
.target.is-complete { border-color: #257836; color: #fff; background: #257836; }
.target.is-wrong { animation: shake .32s ease-in-out; border-color: #b33f31; background: #fff0ed; }

@keyframes shake { 0%, 100% { transform: translate(-50%, -50%); } 25% { transform: translate(calc(-50% - 6px), -50%); } 75% { transform: translate(calc(-50% + 6px), -50%); } }

.safety-note { margin-top: 14px; padding: 12px 15px; color: #6f6258; font-size: .87rem; line-height: 1.55; }

@media (max-width: 980px) {
  .control-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actions { grid-column: 1 / -1; }
  .board { height: min(74vw, 610px); }
}

@media (max-width: 620px) {
  .app { width: min(100% - 20px, 1180px); padding-top: 16px; }
  .topbar { align-items: stretch; flex-direction: column; padding: 18px; }
  .result-panel { min-width: 0; }
  .result-panel span { flex: 1; }
  .control-panel { grid-template-columns: 1fr; padding: 16px; }
  .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tool-button { white-space: normal; }
  .sequence-guide { align-items: flex-start; flex-direction: column; gap: 4px; }
  .board { min-height: 330px; height: 92vw; }
  .target { width: clamp(43px, 13vw, 62px); }
  .board.is-dense .target { width: clamp(38px, 10.5vw, 44px); }
}
