* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 28px;
  background: #101827;
  color: #f8fafc;
  font-family: "BIZ UDGothic", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

.app-shell {
  width: 100%;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 820px;
  margin: 0 auto 18px;
}

h1 {
  margin: 0;
  color: #d8b4fe;
  font-size: 32px;
  line-height: 1.2;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.mode-switch,
.language-switch {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 4px;
  padding: 4px;
  background: #1f2937;
  border: 1px solid #334155;
  border-radius: 999px;
}

.mode-button,
.language-button {
  min-width: 42px;
  min-height: 34px;
  padding: 0 10px;
  color: #cbd5e1;
  background: transparent;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.mode-button {
  min-width: 74px;
}

.mode-button.is-active,
.language-button.is-active {
  color: #101827;
  background: #bbf7d0;
}

.mode-button:focus-visible,
.language-button:focus-visible {
  outline: 2px solid #a78bfa;
  outline-offset: 2px;
}

.offline-status {
  max-width: 820px;
  margin: -6px auto 12px;
  padding: 8px 12px;
  color: #fef3c7;
  background: #78350f;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.chat-examples {
  display: grid;
  gap: 8px;
  margin: -2px 0 14px;
}

.example-button {
  width: 100%;
  padding: 10px 12px;
  color: #e5e7eb;
  background: #263449;
  border: 1px solid #475569;
  border-radius: 8px;
  font: inherit;
  line-height: 1.55;
  text-align: left;
  cursor: pointer;
}

.example-button:hover,
.example-button:focus-visible {
  background: #334155;
  border-color: #a78bfa;
  outline: none;
}

.example-button:active {
  transform: translateY(1px);
}

#chat {
  width: 100%;
  max-width: 820px;
  height: min(62vh, 520px);
  min-height: 360px;
  margin: 0 auto 12px;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  background: #1f2937;
  border: 1px solid #334155;
  border-radius: 8px;
  line-height: 1.75;
  word-break: normal;
  overflow-wrap: anywhere;
}

#chat p {
  margin: 0 0 14px;
  white-space: normal;
}

#chat p:last-child {
  margin-bottom: 0;
}

#chat b {
  color: #bbf7d0;
}

.doubles-preview {
  width: 100%;
  max-width: 820px;
  margin: 0 auto 12px;
  padding: 14px;
  background: #172033;
  border: 1px solid #334155;
  border-radius: 8px;
}

.doubles-preview[hidden] {
  display: none;
}

.doubles-preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.preview-kicker {
  margin: 0 0 4px;
  color: #93c5fd;
  font-size: 12px;
  font-weight: 700;
}

.doubles-preview h2 {
  margin: 0;
  color: #f8fafc;
  font-size: 18px;
  line-height: 1.3;
}

.preview-badge {
  flex: 0 0 auto;
  padding: 4px 8px;
  color: #101827;
  background: #bbf7d0;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.doubles-tool {
  display: grid;
  gap: 10px;
}

.doubles-slots {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.doubles-slots .player-side {
  order: 1;
}

.doubles-slots .opponent-side {
  order: 2;
}

.battle-board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}

.team-side,
.speed-lane,
.threat-grid {
  min-width: 0;
  background: #1f2937;
  border: 1px solid #334155;
  border-radius: 8px;
}

.team-side {
  padding: 10px;
}

.double-slot {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.double-slot span,
.double-attack-row span {
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
}

.double-slot input,
.double-attack-row input,
.double-attack-row select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
  color: #0f172a;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
}

.double-slot input:focus,
.double-attack-row input:focus,
.double-attack-row select:focus {
  border-color: #a78bfa;
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.24);
  outline: none;
}

.double-action-button {
  min-height: 40px;
  padding: 0 12px;
  color: #101827;
  background: #bbf7d0;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.double-action-button:hover,
.double-action-button:focus-visible {
  background: #86efac;
  outline: none;
}

.double-target-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #1f2937;
  border: 1px solid #334155;
  border-radius: 8px;
}

.double-attack-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 112px;
  gap: 8px;
  align-items: center;
}

.double-result {
  min-height: 48px;
  padding: 10px 12px;
  color: #e5e7eb;
  background: #111827;
  border: 1px solid #334155;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.double-result strong {
  color: #bbf7d0;
}

.side-label,
.speed-lane p {
  margin: 0 0 8px;
  color: #c4b5fd;
  font-size: 12px;
  font-weight: 700;
}

.slot-grid {
  display: grid;
  gap: 8px;
}

.field-slot {
  min-height: 64px;
  padding: 10px;
  background: #263449;
  border: 1px solid #475569;
  border-radius: 8px;
}

.field-slot.is-threatened {
  border-color: #f87171;
  box-shadow: inset 3px 0 0 #f87171;
}

.slot-name,
.slot-meta {
  display: block;
  min-width: 0;
}

.slot-name {
  color: #f8fafc;
  font-weight: 700;
  line-height: 1.35;
}

.slot-meta {
  margin-top: 4px;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.45;
}

.speed-lane {
  padding: 10px;
}

.speed-lane ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  color: #e5e7eb;
  font-size: 12px;
  line-height: 1.45;
}

.threat-grid {
  display: grid;
  margin-top: 10px;
  overflow: hidden;
}

.threat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(78px, 0.75fr) minmax(78px, 0.75fr);
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border-top: 1px solid #334155;
  font-size: 13px;
  line-height: 1.45;
}

.threat-row:first-child {
  border-top: 0;
}

.threat-head {
  color: #c4b5fd;
  background: #111827;
  font-size: 12px;
  font-weight: 700;
}

.threat-row strong {
  color: #bbf7d0;
}

.result-line {
  display: grid;
  grid-template-columns: 5em 1em minmax(0, 1fr);
  align-items: start;
  margin: 2px 0;
  line-height: 1.65;
}

.result-label {
  color: #c4b5fd;
  text-align: right;
  white-space: nowrap;
}

.result-separator {
  color: #c4b5fd;
  white-space: nowrap;
}

.result-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.battle-side-value {
  display: grid;
  gap: 2px;
}

.result-details {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid #334155;
}

.result-details summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  color: #bbf7d0;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.result-details summary::marker {
  content: "";
}

.result-details summary::-webkit-details-marker {
  display: none;
}

.result-details summary::before {
  content: "▶";
  color: #bbf7d0;
  font-size: 12px;
  line-height: 1;
}

.result-details[open] summary::before {
  content: "▼";
}

.result-detail-body {
  margin-top: 4px;
}

#input,
#send {
  min-height: 44px;
  font: inherit;
}

#input {
  display: inline-block;
  width: min(680px, calc(100% - 112px));
  padding: 0 14px;
  margin-left: max(0px, calc((100% - 820px) / 2));
  color: #0f172a;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  outline: none;
  vertical-align: top;
}

#input:focus {
  border-color: #a78bfa;
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.28);
}

#send {
  width: 92px;
  margin-left: 8px;
  color: #ffffff;
  background: #7c3aed;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  vertical-align: top;
}

#send:hover {
  background: #6d28d9;
}

#send:active {
  transform: translateY(1px);
}

.below-composer {
  width: 100%;
  max-width: 820px;
  margin: 12px auto 0;
}

.disclaimer {
  margin: 0;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.65;
}

.feedback-link,
.social-link {
  margin: 8px 0 0;
  color: #dbeafe;
  font-size: 13px;
  line-height: 1.6;
}

.feedback-link a,
.social-link a {
  color: #bbf7d0;
  font-weight: 700;
  text-underline-offset: 3px;
}

.feedback-link a:hover,
.feedback-link a:focus-visible,
.social-link a:hover,
.social-link a:focus-visible {
  color: #ffffff;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.6;
}

.footer-links a {
  color: #bbf7d0;
  font-weight: 700;
  text-underline-offset: 3px;
}

.footer-links a:hover,
.footer-links a:focus-visible {
  color: #ffffff;
}

.ad-slot {
  display: grid;
  place-items: center;
  min-height: 72px;
  margin-top: 12px;
  color: #94a3b8;
  background: #172033;
  border: 1px dashed #475569;
  border-radius: 8px;
  font-size: 12px;
}

.content-page {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 18px;
  background: #1f2937;
  border: 1px solid #334155;
  border-radius: 8px;
  line-height: 1.8;
}

.content-page h2 {
  margin: 0 0 12px;
  color: #f8fafc;
  font-size: 24px;
  line-height: 1.3;
}

.content-page h3 {
  margin: 22px 0 8px;
  color: #c4b5fd;
  font-size: 17px;
}

.content-page p,
.content-page ul {
  margin: 0 0 12px;
}

.content-page li {
  margin-bottom: 6px;
}

.content-page a {
  color: #bbf7d0;
  font-weight: 700;
  text-underline-offset: 3px;
}

.back-link {
  display: inline-block;
  margin-bottom: 14px;
  color: #bbf7d0;
  font-weight: 700;
  text-underline-offset: 3px;
}

@media screen and (max-width: 600px) {
  body {
    padding: 16px;
  }

  .app-header {
    margin-bottom: 14px;
  }

  .header-controls {
    align-items: flex-end;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .mode-button,
  .language-button {
    min-width: 38px;
    min-height: 32px;
    padding: 0 8px;
    font-size: 12px;
  }

  .mode-button {
    min-width: 68px;
  }

  .chat-examples {
    gap: 7px;
    margin-bottom: 12px;
  }

  .example-button {
    padding: 9px 10px;
    font-size: 14px;
    line-height: 1.5;
  }

  .doubles-preview {
    padding: 12px;
  }

  .doubles-preview-header {
    align-items: stretch;
  }

  .battle-board {
    grid-template-columns: 1fr;
  }

  .doubles-slots {
    grid-template-columns: 1fr;
  }

  .double-attack-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .speed-lane ol {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding-left: 18px;
  }

  .threat-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
  }

  .threat-head {
    display: none;
  }

  #chat {
    height: 62vh;
    min-height: 360px;
    padding: 14px;
    font-size: 15px;
    line-height: 1.7;
    border-radius: 8px;
  }

  #chat p {
    margin-bottom: 12px;
  }

  .result-line {
    grid-template-columns: 4.8em 1em minmax(0, 1fr);
    line-height: 1.65;
  }

  #input,
  #send {
    min-height: 46px;
    font-size: 16px;
  }

  #input {
    width: calc(100% - 74px);
    margin-left: 0;
    padding: 0 12px;
  }

  #send {
    width: 66px;
    margin-left: 4px;
  }

  .below-composer {
    margin-top: 10px;
  }

  .ad-slot {
    min-height: 64px;
  }
}

@media screen and (max-width: 380px) {
  body {
    padding: 12px;
  }

  h1 {
    font-size: 22px;
  }

  .app-header {
    align-items: flex-start;
  }

  .header-controls {
    width: 100%;
  }

  .mode-switch,
  .language-switch {
    width: 100%;
  }

  .mode-button,
  .language-button {
    flex: 1;
  }

  #chat {
    min-height: 180px;
    font-size: 14px;
  }

  #input {
    width: 100%;
    margin-bottom: 8px;
  }

  #send {
    width: 100%;
    margin-left: 0;
  }
}
