/***********************************************************
  My Web Service / HTML Entity Converter
  Version: 3.1
***********************************************************/

/*----------------------------------------------------------
  デザイントークン

  :root ではなくコンテナに定義することで、テーマや他プラグインの
  同名変数（--primary など）を上書きしない。
  :where() を使っているので詳細度は 0 のまま。
----------------------------------------------------------*/
:where(.entity-converter-wrap, .my-web-service-container) {
  --hec-primary: #46757e;
  --hec-primary-light: #eff6f7;
  --hec-primary-dark: #3a6169;
  --hec-accent: #d4a373;

  --hec-text-main: #1a202c;
  --hec-text-sub: #4a5568;
  --hec-text-muted: #6b7c93;

  --hec-danger: #b3402f;
  --hec-success: #1f7a4d;

  --hec-bg-page: #f8fafc;
  --hec-bg-card: #ffffff;

  /* 枠線は用途で3段階に分ける */
  --hec-border-strong: #cbd5e0; /* 操作できる要素の枠。コントラスト比 3:1 以上 */
  --hec-border: #e2e8f0;        /* 区切り線 */
  --hec-border-soft: #edf2f7;   /* 面の塗り分け */

  --hec-cat-business: #e67e22;
  --hec-cat-diagnostic: #27ae60;
  --hec-cat-cardmaker: #8e44ad;

  --hec-shadow-md: 0 10px 25px -5px rgba(70, 117, 126, 0.1),
    0 8px 10px -6px rgba(70, 117, 126, 0.05);
  --hec-shadow-lg: 0 20px 50px -12px rgba(70, 117, 126, 0.15);

  --hec-radius-lg: 24px;
  --hec-radius-md: 12px;

  --hec-font-sans: "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans",
    "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  --hec-font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --hec-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --hec-transition-ui: background-color 0.2s var(--hec-ease),
    border-color 0.2s var(--hec-ease), color 0.2s var(--hec-ease),
    box-shadow 0.2s var(--hec-ease), transform 0.2s var(--hec-ease),
    opacity 0.2s var(--hec-ease);
}

/* テーマ側に box-sizing のリセットが無くてもレイアウトが崩れないように */
.entity-converter-wrap,
.entity-converter-wrap *,
.entity-converter-wrap *::before,
.entity-converter-wrap *::after,
.my-web-service-container,
.my-web-service-container * {
  box-sizing: border-box;
}

.entity-converter-wrap [hidden] {
  display: none !important;
}

/* 途中で改行させたくない語に付ける */
.entity-converter-wrap .nobr {
  white-space: nowrap;
}

/***********************************************************
  サービス一覧
  ※ このセクションはコンバーターとは別ページでも使うため、
     必要なら別ファイルに切り出してテーマ側で読み込むこと。
***********************************************************/
.my-web-service-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 100px 24px;
  background-color: var(--hec-bg-page);
  color: var(--hec-text-main);
  font-family: var(--hec-font-sans);
  line-height: 1.6;
}

.my-web-service-header {
  margin-bottom: 80px;
  text-align: center;
}

.my-web-service-title {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--hec-primary);
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}

.my-web-service-subtitle {
  font-size: 1.25rem;
  color: var(--hec-text-sub);
  max-width: 600px;
  margin: 0 auto;
  font-weight: 400;
}

.my-web-service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: 40px;
}

.my-web-service-item {
  display: flex;
  flex-direction: column;
  background: var(--hec-bg-card);
  border-radius: var(--hec-radius-lg);
  padding: 40px;
  box-shadow: var(--hec-shadow-md);
  transition: var(--hec-transition-ui);
  border: 1px solid var(--hec-border);
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

.my-web-service-item:hover,
.my-web-service-item:focus-visible {
  transform: translateY(-10px);
  box-shadow: var(--hec-shadow-lg);
  border-color: var(--hec-primary);
}

.my-web-service-item:focus-visible {
  outline: 3px solid var(--hec-primary);
  outline-offset: 3px;
}

.my-web-service-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 6px;
  height: 100%;
}

.category-business::before {
  background: var(--hec-cat-business);
}
.category-diagnostic::before {
  background: var(--hec-cat-diagnostic);
}
.category-cardmaker::before {
  background: var(--hec-cat-cardmaker);
}

.my-web-service-item h3 {
  margin: 0 0 16px;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--hec-text-main);
}

.my-web-service-item p {
  font-size: 1rem;
  color: var(--hec-text-sub);
  line-height: 1.7;
}

/***********************************************************
  HTML Entity Converter
***********************************************************/
.entity-converter-wrap {
  max-width: 1000px;
  margin: 40px auto;
  background: var(--hec-bg-card);
  padding: 50px;
  border-radius: var(--hec-radius-lg);
  box-shadow: var(--hec-shadow-lg);
  font-family: var(--hec-font-sans);
  color: var(--hec-text-main);
  line-height: 1.6;
}

.entity-main-title {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--hec-primary);
  margin-top: 0;
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

.entity-lead-text {
  text-align: center;
  color: var(--hec-text-sub);
  font-size: 0.95rem;
  /* 日本語は em 基準のほうが行長が安定する */
  max-width: 34em;
  margin: 0 auto 40px;
  line-height: 1.8;
  /* 対応ブラウザでは文節単位で折り返す。非対応でも .nobr が効く */
  word-break: auto-phrase;
}

.entity-lead-text code {
  font-family: var(--hec-font-mono);
  background: var(--hec-border-soft);
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: 0.05em;
}

/*----------------------------------------------------------
  ラベル行（ラベル＋補助操作 / 文字数）
----------------------------------------------------------*/
.entity-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.entity-label {
  display: block;
  margin-bottom: 0;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--hec-primary);
}

.entity-count {
  font-size: 0.8rem;
  color: var(--hec-text-muted);
  font-variant-numeric: tabular-nums;
}

.entity-link-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--hec-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  transition: var(--hec-transition-ui);
}

.entity-link-btn:hover {
  color: var(--hec-primary-dark);
}

.entity-link-btn:focus-visible {
  outline: 3px solid var(--hec-primary);
  outline-offset: 3px;
  border-radius: 4px;
}

/*----------------------------------------------------------
  テキストエリア
----------------------------------------------------------*/
.entity-textarea {
  display: block;
  width: 100%;
  padding: 20px;
  border: 2px solid var(--hec-border-soft);
  border-radius: var(--hec-radius-md);
  font-family: var(--hec-font-mono);
  font-size: 15px;
  line-height: 1.6;
  color: var(--hec-text-main);
  background-color: #fcfdfe;
  transition: var(--hec-transition-ui);
  resize: vertical;
}

.entity-textarea--input {
  min-height: 240px;
}

/* 結果欄は最初を低くして、内容に応じて伸ばす（対応ブラウザのみ） */
.entity-textarea--output {
  min-height: 160px;
  max-height: 60vh;
  field-sizing: content;
  background-color: #f7fafc;
  border-color: var(--hec-border);
}

/* マウス操作では枠線を出さず、キーボード操作では明示する */
.entity-textarea:focus-visible {
  outline: none;
  background-color: #fff;
  border-color: var(--hec-primary);
  box-shadow: 0 0 0 4px var(--hec-primary-light);
}

.entity-textarea:focus:not(:focus-visible) {
  outline: none;
  border-color: var(--hec-primary);
}

/*----------------------------------------------------------
  オプション
----------------------------------------------------------*/
.entity-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 30px;
  margin: 30px 0;
  padding: 25px;
  background: var(--hec-primary-light);
  border-radius: var(--hec-radius-md);
  border: 1px solid rgba(70, 117, 126, 0.12);
}

.option-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--hec-primary-dark);
  cursor: pointer;
}

/* 出力形式のオプションと、動作モードの切り替えを視覚的に分ける */
.option-item--mode {
  margin-left: auto;
  padding-left: 24px;
  border-left: 1px solid rgba(70, 117, 126, 0.25);
}

.option-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--hec-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.option-item code {
  font-family: var(--hec-font-mono);
  font-size: 0.9em;
}

/*----------------------------------------------------------
  ボタン
----------------------------------------------------------*/
.entity-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin: 30px 0 40px;
}

.entity-btn {
  padding: 16px 32px;
  border-radius: var(--hec-radius-md);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
  transition: var(--hec-transition-ui);
  cursor: pointer;
}

.entity-btn:focus-visible {
  outline: 3px solid var(--hec-primary);
  outline-offset: 2px;
}

.entity-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.entity-btn:disabled:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--hec-border-strong);
  color: var(--hec-text-sub);
  background: #fff;
}

.btn-convert:disabled:hover {
  background: var(--hec-primary);
  color: #fff;
}

/* flex-basis を 0 にしないとテキスト量に引きずられて比率が崩れる */
.btn-convert {
  flex: 3 1 0;
  background: var(--hec-primary);
  color: #fff;
  border: none;
}

.btn-convert:not(:disabled):hover {
  background: var(--hec-primary-dark);
  transform: scale(1.02);
  box-shadow: 0 10px 20px rgba(70, 117, 126, 0.2);
}

.btn-sub {
  flex: 1 1 0;
  background: #fff;
  color: var(--hec-text-main);
  border: 2px solid var(--hec-border-strong);
}

.btn-sub:not(:disabled):hover {
  border-color: var(--hec-primary);
  color: var(--hec-primary);
}

/* 破壊的な操作なので、コピーから物理的に離す */
.btn-clear {
  margin-left: auto;
  flex-grow: 0;
  color: var(--hec-text-sub);
}

.btn-clear:not(:disabled):hover {
  border-color: var(--hec-danger);
  color: var(--hec-danger);
}

.btn-undo {
  flex: 0 1 auto;
  background: #fff;
  color: var(--hec-primary-dark);
  border: 2px dashed var(--hec-primary);
}

.btn-undo:hover {
  background: var(--hec-primary-light);
}

/*----------------------------------------------------------
  通知

  visibility: hidden はアクセシビリティツリーから外れて
  aria-live が機能しなくなるため使わない。
  高さは grid-template-rows の 0fr → 1fr で開閉する。
----------------------------------------------------------*/
.copy-notice {
  display: grid;
  grid-template-rows: 0fr;
  margin: 0;
  padding: 0 12px;
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
  color: var(--hec-success);
  background: #f0fff4;
  opacity: 0;
  transition: grid-template-rows 0.25s var(--hec-ease),
    opacity 0.25s var(--hec-ease), padding 0.25s var(--hec-ease),
    margin 0.25s var(--hec-ease);
}

.copy-notice-inner {
  overflow: hidden;
  min-height: 0;
}

.copy-notice.show-notice {
  grid-template-rows: 1fr;
  opacity: 1;
  padding: 12px;
  margin-top: 16px;
}

.copy-notice.is-error {
  color: var(--hec-danger);
  background: #fff5f5;
}

/***********************************************************
  使い方ガイド
***********************************************************/
.entity-guide-section {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--hec-border-strong);
}

.entity-guide-heading {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--hec-primary);
  margin: 0 0 24px;
  /* 下のカードが左揃えなので見出しも揃える */
  text-align: left;
}

.entity-guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  /* 項目数が違うカードの高さを引き伸ばさない */
  align-items: start;
  gap: 30px;
}

.entity-guide-block {
  background: var(--hec-bg-page);
  padding: 24px;
  border-radius: var(--hec-radius-md);
  border: 1px solid var(--hec-border-soft);
}

.entity-guide-sub-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--hec-primary-dark);
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--hec-primary-light);
}

.entity-guide-list {
  margin: 0;
  padding-left: 20px;
  font-size: 0.9rem;
  color: var(--hec-text-sub);
  line-height: 1.8;
}

.entity-guide-list li:not(:last-child) {
  margin-bottom: 12px;
}

/* チップが途中で改行されて背景が割れるのを防ぐ */
.entity-guide-list code,
.option-item code {
  display: inline-block;
  white-space: nowrap;
  background: var(--hec-border-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--hec-font-mono);
  font-size: 0.85rem;
  color: var(--hec-primary-dark);
  vertical-align: 0.05em;
}

.option-item code {
  background: rgba(255, 255, 255, 0.7);
}

.entity-guide-note {
  margin-top: 24px;
  font-size: 0.85rem;
  color: var(--hec-text-muted);
  text-align: center;
  font-weight: 600;
}

/***********************************************************
  レスポンシブ
***********************************************************/
@media (max-width: 768px) {
  .my-web-service-container {
    padding: 60px 16px;
  }
  .my-web-service-header {
    margin-bottom: 50px;
  }
  .my-web-service-title {
    font-size: 2rem;
  }
  .my-web-service-item {
    padding: 28px;
  }

  .entity-converter-wrap {
    padding: 24px;
    margin: 20px auto;
    border-radius: var(--hec-radius-md);
  }
  .entity-main-title {
    font-size: 1.8rem;
  }

  .entity-options {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
    padding: 20px;
  }
  /* 縦積みでは左寄せの区切りに切り替える */
  .option-item--mode {
    margin-left: 0;
    padding-left: 0;
    padding-top: 15px;
    border-left: none;
    border-top: 1px solid rgba(70, 117, 126, 0.25);
    width: 100%;
  }

  .entity-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-clear {
    margin-left: 0;
    margin-top: 8px;
  }

  .entity-textarea {
    font-size: 16px; /* iOS の自動ズームを防ぐ */
  }
  .entity-textarea--input {
    min-height: 180px;
  }
  .entity-textarea--output {
    min-height: 140px;
  }
}

/***********************************************************
  モーション削減設定への配慮
***********************************************************/
@media (prefers-reduced-motion: reduce) {
  .entity-converter-wrap *,
  .my-web-service-container * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }

  .my-web-service-item:hover,
  .btn-convert:not(:disabled):hover {
    transform: none;
  }
}