/* =========================================================
   モルキのメモカード ー 共通CSS
   フカボリカラーズ全体で使い回す「単語カードUI」の土台。
   カテゴリーカラーやフォントはここを直せば全ページに反映される。
========================================================= */

.morukey-root{
  --bench-dark:#241d17;
  --bench-mid:#2f261e;
  --bench-line:#1a140f;
  --paper:#fbf3e2;
  --paper-back:#f4e9d2;
  --paper-shadow:#e3d3ac;
  --ink:#3c2f22;
  --ink-soft:#7a6b54;

  --cat-daily:#e0a83c;
  --cat-daily-deep:#8a5f13;
  --cat-dev:#4f9aa6;
  --cat-dev-deep:#1f5960;
  --cat-make:#dd7452;
  --cat-make-deep:#8a3c22;

  font-family:'Zen Maru Gothic', sans-serif;
  color:var(--paper);
}

.morukey-root *{ box-sizing:border-box; }

/* ---------- category tabs ---------- */
.morukey-tabs{
  display:flex;
  gap:5px;
  margin-bottom:12px;
  flex-wrap:nowrap;
  justify-content:center;
  overflow-x:auto;
  scrollbar-width:none;
  -webkit-overflow-scrolling:touch;
}
.morukey-tabs.is-below{ margin-bottom:0; margin-top:18px; }
.morukey-tabs::-webkit-scrollbar{ display:none; }
.morukey-tab{
  display:flex;align-items:center;gap:4px;
  padding:6px 11px;
  border-radius:999px;
  border:1.5px solid rgba(255,255,255,0.18);
  background:rgba(255,255,255,0.05);
  color:var(--ink);
  font-weight:500;
  font-size:12.5px;
  white-space:nowrap;
  flex-shrink:0;
  cursor:pointer;
  transition:transform .18s ease, background .2s ease;
  user-select:none;
}
.morukey-tab:hover{ transform:translateY(-1px); }
.morukey-tab.active{
  background:var(--tab-color,#eadfc7);
  color:var(--tab-color-deep,#3c2f22);
  border-color:transparent;
  box-shadow:0 4px 10px rgba(0,0,0,0.25);
}
.morukey-tab[data-cat="all"]{ --tab-color:#eadfc7; --tab-color-deep:#3c2f22; }
.morukey-tab[data-cat="daily"]{ --tab-color:var(--cat-daily); --tab-color-deep:var(--cat-daily-deep); }
.morukey-tab[data-cat="dev"]{ --tab-color:var(--cat-dev); --tab-color-deep:var(--cat-dev-deep); }
.morukey-tab[data-cat="make"]{ --tab-color:var(--cat-make); --tab-color-deep:var(--cat-make-deep); }

/* ---------- stand / stack ---------- */
.morukey-stand-row{
  display:flex;
  align-items:center;
  gap:10px;
}
.morukey-nav-btn{
  width:38px;height:38px;
  border-radius:50%;
  border:none;
  background:rgba(255,255,255,0.08);
  color:#eadfc7;
  font-size:18px;
  cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  transition:background .2s ease, transform .12s ease;
  flex-shrink:0;
}
.morukey-nav-btn:hover{ background:rgba(255,255,255,0.16); }
.morukey-nav-btn:active{ transform:scale(0.9); }

.morukey-stand{
  position:relative;
  width:min(92vw, 480px);
  margin:0 auto;
  padding-top:clamp(48px, 14.5cqw, 68px);
  container-type:inline-size;   /* ring size is relative to the widget's OWN width, not the page */
  container-name:morukey-stand;
}
.morukey-root.is-compact .morukey-stand{ width:100%; padding-top:clamp(46px, 15cqw, 56px); }
.morukey-root.is-compact .morukey-stack-layer{ top:clamp(46px, 15cqw, 56px); }

.morukey-stack-layer{
  position:absolute;
  top:clamp(48px, 14.5cqw, 68px); left:0; right:0;
  aspect-ratio:2.15 / 1;
  border-radius:14px;
  background:var(--paper-shadow);
  box-shadow:0 6px 14px rgba(0,0,0,0.3);
}
.morukey-stack-layer.l1{ transform:translate(3px,5px) rotate(0.9deg); opacity:0.9; z-index:1;}
.morukey-stack-layer.l2{ transform:translate(6px,10px) rotate(-1.1deg); opacity:0.75; z-index:0;}
.morukey-stack-layer.l1.nudge{ animation:morukeyPaperNudge .5s ease; }
@keyframes morukeyPaperNudge{
  0%{ transform:translate(3px,5px) rotate(0.9deg); }
  35%{ transform:translate(4.5px,6.5px) rotate(1.6deg); }
  100%{ transform:translate(3px,5px) rotate(0.9deg); }
}

/* ---------- archive: ring-centered two-sheet card stack ----------
   本物の単語カードの再現。
   - .morukey-card-slot が「まだめくっていない紙が積まれている場所」＝下のスロット。
     ここに peek(次のカード/JP、常に存在)と scene(今読んでいるカード)が
     まったく同じ位置・同じ大きさで重なっている。
   - めくる = .morukey-card がリング(hinge, 上端)を軸にrotateXで実際に
     スロットの外(上)へスイングする。retreat先の「上の空間」は
     .morukey-stand の padding-top として最初から確保してあるだけで、
     専用のDOM要素は存在しない(＝新しい場所を作っているわけではない)。
   - peek は opacity を一切使わず、常にそこに存在し続ける。上のカードが
     退いた結果として、z-indexの下からそのまま覗けるだけ。 */
.morukey-stand.is-stack{
  padding-top:calc(100% / 2.15); /* めくったカード(EN)がリングの上へ収まるための headroom */
}
.morukey-stack-hinge{
  position:relative;
  height:0;
  z-index:6;
}
/* .morukey-ring 自体のCSS(絶対配置 + translateY(-50%))はそのまま使い回せる。
   height:0 の hinge を基準にすることで、境界線ちょうどにリングの中心が来る。 */

.morukey-card-slot{
  position:relative;
  width:100%;
  aspect-ratio:2.15 / 1;
}
.morukey-stand.is-stack .morukey-scene{
  position:absolute;
  inset:0;
  width:auto;
  aspect-ratio:auto;
}

.morukey-peek-scene{
  position:absolute;
  inset:0;
  z-index:1;
  border-radius:14px;
  cursor:pointer;
  box-shadow:0 14px 24px rgba(0,0,0,0.35), 0 2px 0 rgba(255,255,255,0.4) inset;
  background-color:var(--paper);
  background-image:
    radial-gradient(circle at 88% 92%, rgba(0,0,0,0.05), transparent 40%),
    radial-gradient(circle at 8% 6%, rgba(255,255,255,0.5), transparent 35%);
  display:flex;
  flex-direction:column;
  padding:clamp(10px,2.6vw,18px) clamp(14px,3.5vw,22px) clamp(10px,2.6vw,16px);
}
/* めくり終わった(state.flipped=true)後は、3Dの見た目上の退避だけに頼らず、
   peek-scene を明示的に前面へ。ブラウザごとの3D当たり判定のばらつきに
   左右されず、確実にクリックできるようにするための安全策。 */
.morukey-card-slot.is-flipped .morukey-peek-scene{ z-index:3; }
.morukey-card-slot.is-flipped .morukey-scene{ z-index:1; }

.morukey-peek-face{
  display:flex;
  flex-direction:column;
  flex:1;
  min-height:0;
}
.morukey-peek-scene.is-end .morukey-peek-face{ display:none; }

/* ---------- archive: read-to-the-end state (同じ peek-scene の中で表示が入れ替わる) ---------- */
.morukey-peek-end{
  display:none;
  flex:1;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:12px;
  text-align:center;
}
.morukey-peek-scene.is-end .morukey-peek-end{ display:flex; }
.morukey-peek-end p{
  margin:0;
  font-family:'Zen Maru Gothic', sans-serif;
  color:var(--ink);
  font-size:14px;
}
.morukey-restart-btn{
  border:1.5px solid var(--paper-shadow);
  background:rgba(60,47,34,0.05);
  color:var(--ink);
  border-radius:999px;
  padding:9px 20px;
  font-family:'Zen Maru Gothic', sans-serif;
  font-size:13px;
  cursor:pointer;
  display:flex;
  flex-direction:column;
  gap:2px;
  transition:transform .15s ease, background .2s ease;
}
.morukey-restart-btn:hover{ transform:translateY(-1px); background:rgba(60,47,34,0.1); }
/* ラベル(.morukey-restart-label)とサブテキスト(.morukey-restart-sub)の2つのspanに
   分かれている(UI言語切替でラベル側にルビHTMLを差し込むため)。
   見た目は元のまま:サブテキストのみ小さいQuicksandフォントで表示。 */
.morukey-restart-btn .morukey-restart-sub{
  font-family:'Quicksand', sans-serif;
  font-size:10px;
  color:var(--ink-soft);
}

/* ---------- card number badge (archiveのみ／JP・ENの右) ---------- */
.morukey-card-num{
  width:17px;height:17px;
  border-radius:50%;
  border:1px solid var(--paper-shadow);
  color:var(--ink-soft);
  font-size:9px;
  font-weight:700;
  font-family:'Quicksand', sans-serif;
  display:flex;align-items:center;justify-content:center;
  flex-shrink:0;
}

/* ---------- flip scene ---------- */
.morukey-scene{
  position:relative;
  width:100%;
  aspect-ratio:2.15 / 1;
  perspective:1300px;
  z-index:2;
  touch-action:pan-y;
}
.morukey-scene.switching{ animation:morukeySceneSwitch .3s ease; }
@keyframes morukeySceneSwitch{
  0%{ opacity:0; transform:translateY(6px) scale(0.98); }
  100%{ opacity:1; transform:translateY(0) scale(1); }
}

.morukey-card{
  position:absolute;
  inset:0;
  border-radius:14px;
  cursor:pointer;
  transform-style:preserve-3d;
  transform-origin:50% 4px;   /* hinge along the top edge, right where the ring sits */
  will-change:transform;
}

.morukey-face{
  position:absolute;
  inset:0;
  border-radius:14px;
  backface-visibility:hidden;
  box-shadow:0 14px 24px rgba(0,0,0,0.35), 0 2px 0 rgba(255,255,255,0.4) inset;
  display:flex;
  flex-direction:column;
  padding:clamp(10px,2.6vw,18px) clamp(14px,3.5vw,22px) clamp(10px,2.6vw,16px);
  background-image:
    radial-gradient(circle at 88% 92%, rgba(0,0,0,0.05), transparent 40%),
    radial-gradient(circle at 8% 6%, rgba(255,255,255,0.5), transparent 35%);
}
.morukey-face.front{ background-color:var(--paper); }
.morukey-face.back{
  transform:rotateX(180deg);
  background-color:var(--paper-back);
  background-image:
    repeating-linear-gradient(180deg, transparent 0px, transparent 25px, rgba(60,47,34,0.08) 26px),
    radial-gradient(circle at 92% 92%, rgba(0,0,0,0.05), transparent 40%);
}

/* rings: fixed images, positioned relative to the widget's own width (container query units) */
.morukey-ring{
  position:absolute;
  top:0;                              /* 0 = the card's own top edge (scene is the ring's positioning context now) */
  transform:translateY(-50%);         /* shift up by exactly half the ring's own height, whatever that height is */
  --ring-h: clamp(88px, 28cqw, 128px);
  height:var(--ring-h);
  width:clamp(44px, 13cqw, 64px);
  object-fit:contain;
  z-index:6;
  pointer-events:none;
  filter:drop-shadow(0 4px 5px rgba(0,0,0,0.5));
}
.morukey-ring.left{ left:clamp(26px, 11cqw, 48px); }
.morukey-ring.right{ right:clamp(26px, 11cqw, 48px); }

.morukey-face-top{
  display:flex;
  justify-content:flex-end;
  flex-shrink:0;
}
.morukey-cat-icon{
  width:clamp(24px,6vw,32px);
  height:clamp(24px,6vw,32px);
  border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  font-size:clamp(12px,3vw,16px);
  color:#fff;
  flex-shrink:0;
}
.morukey-cat-icon.daily{ background:var(--cat-daily); }
.morukey-cat-icon.dev{ background:var(--cat-dev); }
.morukey-cat-icon.make{ background:var(--cat-make); }

.morukey-face-body{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  padding:2px 4px;
  min-height:0;
  /* no overflow:hidden here on purpose: the JS shrink-to-fit routine guarantees the
     text fits before it is ever shown, so clipping (which caused the cut-off text
     bug) is not needed as a fallback. */
}
.morukey-body-text{
  max-width:100%;
}
.morukey-body-text.jp{
  font-family:'Zen Maru Gothic', sans-serif;
  font-weight:700;
  font-size:18px;
  line-height:1.6;
  color:var(--ink);
}
.morukey-body-text.jp ruby rt{ font-size:0.55em; font-weight:500; color:var(--ink-soft); }

/* ---------- UI要素(タブ・もっと見る・最初から読む)のルビ ----------
   カード本文とは別の場所で使われるルビなので、そちら側の文字サイズに
   合わせて縮小する(色は継承元のテキストカラーをそのまま使う)。 */
.morukey-tab ruby rt,
.morukey-more ruby rt,
.morukey-restart-label ruby rt{
  font-size:0.6em;
}
.morukey-body-text.en{
  font-family:'Quicksand', sans-serif;
  font-weight:600;
  font-size:15px;
  line-height:1.55;
  color:var(--ink);
}

.morukey-face-bottom{
  display:flex;
  flex-direction:row;
  align-items:center;
  justify-content:center;
  gap:8px;
  font-family:'Quicksand', sans-serif;
  flex-shrink:0;
}
.morukey-date{ font-size:clamp(9px,2vw,11px); color:var(--ink-soft); }
.morukey-lang-tag{
  font-size:clamp(9px,1.8vw,10px);
  font-weight:600;
  color:var(--ink-soft);
  border:1px solid var(--paper-shadow);
  border-radius:999px;
  padding:2px 8px;
}

/* ---------- controls (archive / full mode) ---------- */
.morukey-controls{
  margin-top:26px;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:18px;
  flex-wrap:wrap;
}
.morukey-sound-toggle{
  display:flex;align-items:center;gap:8px;
  font-size:13px;
  color:#d8cbac;
  cursor:pointer;
  user-select:none;
}
.morukey-switch{
  width:38px;height:22px;
  border-radius:999px;
  background:rgba(255,255,255,0.15);
  position:relative;
  transition:background .2s ease;
}
.morukey-switch::after{
  content:"";
  position:absolute;
  top:2px;left:2px;
  width:18px;height:18px;
  border-radius:50%;
  background:#eadfc7;
  transition:transform .2s ease;
}
.morukey-sound-toggle.on .morukey-switch{ background:var(--cat-dev); }
.morukey-sound-toggle.on .morukey-switch::after{ transform:translateX(16px); }

.morukey-counter{
  font-size:13px;
  color:#c9bb9c;
  letter-spacing:0.04em;
  font-family:'Quicksand', sans-serif;
}

/* ---------- "read more" link (component mode) ---------- */
.morukey-more{
  display:block;
  text-align:center;
  margin-top:18px;
  font-size:13px;
  color:var(--ink);
  text-decoration:none;
  border-bottom:1px solid rgba(242,226,182,0.4);
  cursor:pointer;
  background:none;
  border-top:none;border-left:none;border-right:none;
  padding:0 0 2px;
  font-family:'Zen Maru Gothic', sans-serif;
  width:fit-content;
  margin-left:auto;
  margin-right:auto;
}

/* title + "もっと見る" sharing a single compact row (component mode) */
.morukey-footer-row{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  margin-top:10px;
}
.morukey-footer-row .morukey-more{
  margin:0;
}
.morukey-footer-title{
  font-family:'Yuji Syuku', serif;
  font-size:13px;
  color:var(--ink);
}
.morukey-footer-title-en{
  font-family:'Quicksand', sans-serif;
  font-size:9px;
  letter-spacing:0.08em;
  color:var(--ink);
}

@media (max-width:380px){
  .morukey-controls{ gap:12px; }
}
