/* チームシートツール - スタイル */

/* 出力画像用フォント（略字少なめトゲトゲ） */
@font-face {
  font-family: "RyakjiToge";
  src: url("ryakji-skname-toge^2.ttf") format("truetype");
  font-display: block;
}

:root {
  --bg: #f4fefd;
  --btn-primary: #2dd4bf;
  --btn-primary-hover: #14b8a6;
  --btn-secondary: #99f6e4;
  --btn-secondary-hover: #5eead4;
  --btn-pressed: #0d9488;
  --text: #134e4a;
  --text-muted: #0f766e;
  --placeholder: #5eead4;
  --border: #99f6e4;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 14px rgba(13, 148, 136, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  position: relative;
}

/* 画面切り替え */
.screen {
  display: none;
  min-height: 100vh;
  padding: 0 0 2rem;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ========== エントランス ========== */
#screen-entrance {
  justify-content: flex-start;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

.app-version {
  position: absolute;
  top: 0.6rem;
  left: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-muted, #aaa);
  pointer-events: none;
  user-select: none;
}

#screen-entrance .btn-past {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
}
#screen-entrance .btn-past:hover {
  background: var(--btn-secondary);
}

.entrance-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  gap: 1.5rem;
}

.btn-load-image {
  width: min(90vw, 320px);
  padding: 1.25rem 2rem;
  font-size: clamp(1.1rem, 4vw, 1.35rem);
  font-weight: bold;
  border-radius: var(--radius);
  border: none;
  background: var(--btn-primary);
  color: white;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.2s, transform 0.1s;
}
.btn-load-image:hover {
  background: var(--btn-primary-hover);
}
.btn-load-image:active {
  transform: scale(0.98);
}

.btn-start-without {
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--btn-secondary);
  color: var(--text);
  cursor: pointer;
}
.btn-start-without:hover {
  background: var(--btn-secondary-hover);
}

#screen-entrance .explanation {
  margin: 0 1.5rem 2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  text-align: center;
}

/* ========== パーティシート設定 ========== */
#screen-sheet {
  padding-top: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.8);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.sheet-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.btn-preview span,
.btn-output span {
  display: inline;
}
@media (max-width: 380px) {
  .btn-preview span,
  .btn-output span {
    display: block;
    line-height: 1.2;
  }
  .btn-preview,
  .btn-output {
    text-align: center;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
  }
}
.btn-preview {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--btn-secondary);
  color: var(--text);
  cursor: pointer;
}
.btn-preview:hover {
  background: var(--btn-secondary-hover);
}

.btn-back {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.btn-back:hover {
  background: var(--btn-secondary);
}

.btn-output {
  padding: 0.6rem 1.25rem;
  font-size: 0.95rem;
  font-weight: bold;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--btn-primary);
  color: white;
  cursor: pointer;
}
.btn-output:hover {
  background: var(--btn-primary-hover);
}

.sheet-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sheet-form {
  width: 100%;
  max-width: 500px;
  margin: 0 auto 2rem;
  padding: 0 1rem;
}

.form-row {
  margin-bottom: 1rem;
}
.form-row label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.form-row input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
}
.form-row input::placeholder {
  color: var(--placeholder);
}

/* ========== 英語出力トグル ========== */
.eng-output-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  background: rgba(0,0,0,0.03);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.eng-output-label {
  font-size: 0.9rem;
  color: var(--text);
}
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 3.5rem;
  height: 2rem;
  border-radius: 1rem;
  border: none;
  background: var(--border);
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-switch[aria-checked="true"] {
  background: var(--btn-primary);
}
.toggle-knob {
  position: absolute;
  left: 0.2rem;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: left 0.2s;
  pointer-events: none;
}
.toggle-switch[aria-checked="true"] .toggle-knob {
  left: calc(100% - 1.8rem);
}
.toggle-label-text {
  position: absolute;
  right: 0.35rem;
  font-size: 0.6rem;
  font-weight: bold;
  color: #999;
  pointer-events: none;
  transition: right 0.2s, color 0.2s;
}
.toggle-switch[aria-checked="true"] .toggle-label-text {
  right: auto;
  left: 0.35rem;
  color: #fff;
}

.sheet-note {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted, #888);
  line-height: 1.7;
  background: rgba(0,0,0,0.03);
  border-left: 3px solid var(--border, #ccc);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.pokemon-slots {
  display: grid;
  grid-template-columns: repeat(2, minmax(168px, 1fr));
  gap: 0.5rem;
  margin-top: 1.5rem;
}
@media (min-width: 600px) {
  .pokemon-slots {
    grid-template-columns: repeat(3, minmax(168px, 1fr));
  }
}

.pokemon-slot {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  cursor: pointer;
  min-width: 0;
}
.pokemon-slot .slot-pokemon-name {
  font-weight: bold;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
  min-height: 1.3em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pokemon-slot .slot-pokemon-name.placeholder {
  color: var(--text-muted);
  font-weight: normal;
}
.pokemon-slot .slot-name-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 0.35rem;
}
.pokemon-slot .slot-pokemon-name.slot-name-btn {
  display: inline-block;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--btn-primary);
  border-radius: var(--radius-sm);
  background: var(--btn-secondary);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: background 0.2s;
}
.pokemon-slot .slot-pokemon-name.slot-name-btn:hover {
  background: var(--btn-secondary-hover);
}
.pokemon-slot .slot-pokemon-name.slot-name-btn.placeholder {
  color: var(--text-muted);
}
.pokemon-slot .slot-pokemon-img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  display: block;
  margin: 0 auto 0.35rem;
  position: relative;
}
.pokemon-slot .slot-pokemon-img--clickable {
  cursor: pointer;
}
.pokemon-slot .slot-pokemon-img--clickable:hover {
  opacity: 0.75;
}
.pokemon-slot .slot-cp {
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}
.pokemon-slot .slot-cp input {
  width: 4.5em;
  padding: 0.25rem 0.4rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-left: 0.25rem;
}
.pokemon-slot .slot-shadow-light {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.35rem 0;
}
.pokemon-slot .slot-shadow-light .shadow-light-btn {
  padding: 0.2rem;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pokemon-slot .slot-shadow-light .shadow-light-btn img {
  width: 24px;
  height: 24px;
  display: block;
}
.pokemon-slot .slot-shadow-light .shadow-light-btn:hover {
  background: var(--btn-secondary);
}
.pokemon-slot .slot-shadow-light .shadow-light-btn.pressed {
  background: var(--btn-pressed);
  border-color: var(--btn-pressed);
}
.pokemon-slot .slot-moves {
  font-size: 0.75rem;
  margin-top: 0.35rem;
}
.pokemon-slot .slot-moves .move-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.2rem;
}
.pokemon-slot .slot-moves .move-select-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
.pokemon-slot .slot-moves .move-row select {
  width: 100%;
  padding: 0.2rem;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  /* 折り畳み状態の選択テキストを透明にし、下のスパンで短縮名を表示する */
  color: transparent;
}
/* ネイティブドロップダウン内の option は通常色で表示 */
.pokemon-slot .slot-moves .move-row select option {
  color: var(--text);
  background: #fff;
}
/* disabled 時はスパンを非表示 */
.pokemon-slot .slot-moves .move-row select:disabled ~ .move-display {
  display: none;
}
.pokemon-slot .slot-moves .move-display {
  position: absolute;
  top: 0;
  left: 0;
  right: 1.1rem; /* ドロップダウン矢印の分を空ける */
  bottom: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  padding: 0 0.25rem;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.pokemon-slot .slot-moves .move-type-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex-shrink: 0;
}

/* ========== 過去の画像 ========== */
#screen-history .sheet-header {
  justify-content: flex-start;
}

.history-list {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 500px;
  margin: 0 auto;
}
.history-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.history-item img {
  width: 100%;
  display: block;
}
.history-item .history-meta {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.history-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
}

/* ========== 検索オーバーレイ ========== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem 4rem;
  overflow-y: auto;
}
.overlay.active {
  display: flex;
}

/* プレビューオーバーレイ */
#overlay-preview {
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#overlay-preview .preview-overlay-backdrop {
  position: absolute;
  inset: 0;
  cursor: pointer;
}
#overlay-preview .preview-overlay-box {
  position: relative;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  padding: 2rem 2rem 1.5rem;
  max-width: 95vw;
  max-height: 90vh;
  overflow: auto;
}
#overlay-preview .btn-close-preview {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: rgba(0,0,0,0.08);
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  z-index: 1;
}
#overlay-preview .btn-close-preview:hover {
  background: rgba(0,0,0,0.15);
}
#overlay-preview .preview-overlay-note {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted, #888);
  text-align: center;
}
#overlay-preview .preview-overlay-content {
  min-width: 200px;
}
#overlay-preview .preview-overlay-content canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.overlay-inner {
  background: var(--bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.search-header {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-header input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.btn-close-overlay {
  flex-shrink: 0;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--btn-secondary);
  cursor: pointer;
  white-space: nowrap;
}

.search-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem;
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
.search-result-item:hover {
  background: var(--btn-secondary);
}
.search-result-item img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
}
.search-result-item span {
  font-size: 0.95rem;
}

/* ========== 処理中オーバーレイ ========== */
.overlay-progress {
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.overlay-progress .progress-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(244, 254, 253, 0.85);
}
.overlay-progress .progress-overlay-box {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 2rem;
  min-width: 240px;
}
.overlay-progress .progress-overlay-hint {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  color: var(--text-muted, #888);
  text-align: center;
  line-height: 1.5;
}
.overlay-progress .progress-overlay-hint2 {
  margin-bottom: 0.6rem;
}
.overlay-progress .progress-overlay-hint[aria-hidden="true"] {
  display: none;
}
.overlay-progress .progress-overlay-text {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--text);
  text-align: center;
}
.overlay-progress .progress-overlay-bar-wrap {
  width: 100%;
  height: 12px;
  background: var(--btn-secondary);
  border-radius: 999px;
  overflow: hidden;
}
.overlay-progress .progress-overlay-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--btn-primary);
  border-radius: 999px;
}

/* ========== 画像認識デバッグオーバーレイ ========== */
.overlay-debug {
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.overlay-debug .debug-overlay-backdrop {
  position: absolute;
  inset: 0;
  cursor: pointer;
}
.overlay-debug .debug-overlay-box {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  padding: 1rem;
  max-width: 95vw;
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border);
}
.overlay-debug .debug-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.overlay-debug .debug-overlay-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text);
}
.overlay-debug .btn-close-debug {
  width: 2rem;
  height: 2rem;
  border: none;
  background: rgba(0,0,0,0.08);
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}
.overlay-debug .btn-close-debug:hover {
  background: rgba(0,0,0,0.15);
}
.overlay-debug #debug-canvas-full {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}
.overlay-debug .debug-cells {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}
.overlay-debug .debug-cell-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
}
.overlay-debug .debug-cell-thumbnails {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}
.overlay-debug .debug-cell-canvas {
  display: block;
  width: 64px;
  height: 64px;
  margin: 0;
  border-radius: 4px;
}
.overlay-debug .debug-cell-canvas.debug-cell-cp {
  width: 48px;
  height: 32px;
}
.overlay-debug .debug-cell-canvas.debug-cell-shadow {
  width: 40px;
  height: 28px;
}
.overlay-debug .debug-cell-info {
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--text);
  word-break: break-all;
}
.overlay-debug .debug-cell-info.debug-cell-cp-sl {
  margin-top: 0.2rem;
  font-size: 0.65rem;
  color: var(--text-muted, #555);
}
