:root{
  --bg:#0f1116; 
  --card:#151826; 
  --panel:#151a22; 
  --ink:#e9eef7; 
  --muted:#a9b4c7;
  --accent:#7aa2ff; 
  --primary:#4ad395; /* 綠色 */
  --danger:#ff6b6b; /* 紅色 */
  --secondary:#8b85fa; /* 新增一個紫色調按鈕顏色 */
  --slot:#2a3042;
  --cardW:120px; 
  --cardH:190px;
}
*{box-sizing:border-box; font-family:'Inter', system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial}
html,body{height:100%;}
body{
  margin:0; 
  background:linear-gradient(180deg,#0b0d12,#121624 40%,#0b0f19);
  color:var(--ink); 
  font-size:16px; 
  line-height:1.5;
}
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 20px; 
  background:#0e1220; 
  border-bottom:1px solid #22283a; 
  position:sticky; top:0; z-index:100;
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.brand{
  font-weight:900; 
  letter-spacing:1px; 
  font-size:1.5rem; 
  color:var(--accent); 
  text-shadow: 0 0 5px rgba(122, 162, 255, 0.4);
}
.controls-group{
  display:flex; gap:15px; align-items:center;
}
.lbl{
  display:flex; flex-direction:column; gap:4px;
  font-size:0.9rem;
}
.input-group{
  width:100%;
}
.input-group input, .controls-section select{
  width:100%;
}
.control-row{
  display:flex; gap:15px; margin-top:15px;
}
.action-buttons, .tool-buttons{
  display:flex; gap:10px; margin-top:15px; flex-wrap:wrap;
}

select, input[type="text"]{
  background:#0e1322; 
  color:var(--ink); 
  border:1px solid #273050; 
  border-radius:8px; 
  padding:8px 12px;
  transition: border-color .2s, box-shadow .2s;
}
select:focus, input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 5px rgba(122, 162, 255, 0.5);
  outline: none;
}
.checkbox-lbl{
  flex-direction: row;
  align-items: center;
  margin-top: 5px; 
}


/* --- Grid Layout --- */
.wrap{
  display:grid; 
  grid-template-columns: minmax(300px, 350px) 1fr; 
  gap:20px; 
  padding:20px; 
  max-width:1400px; 
  margin:0 auto;
}
@media (max-width: 1100px){ 
  .wrap{
    grid-template-columns:1fr; 
    padding:15px;
  } 
  .board{
    order: -1; 
  }
}
.reading-panel{
  background:var(--panel); 
  border:1px solid #1e2536; 
  border-radius:12px; 
  padding:20px;
  box-shadow:0 1px 0 #1a2132 inset, 0 8px 25px rgba(0,0,0,.35);
}
.controls-section{
  padding-bottom: 20px;
  border-bottom: 1px dashed var(--slot);
  margin-bottom: 20px;
}
.reading-output h3{
  margin-top: 0;
  color: var(--accent);
  border-bottom: 2px solid var(--slot);
  padding-bottom: 5px;
}

button{
  appearance:none; 
  border:none; 
  padding:10px 16px; 
  border-radius:10px; 
  cursor:pointer; 
  transition:all .2s ease;
  font-weight: 600;
  box-shadow: 0 3px 6px rgba(0,0,0,.2);
}
button:hover{
  filter: brightness(1.1);
  box-shadow: 0 4px 8px rgba(0,0,0,.3);
}
button:active{
  transform:translateY(1px);
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
}
button.primary{
  background:var(--primary); 
  color:var(--bg);
}
button.secondary{
  background:var(--secondary); 
  color:var(--bg);
}
button.danger{
  background:var(--danger); 
  color:var(--bg);
}
button.ghost{
  background:transparent; 
  border:1px solid #45506e; 
  color:var(--muted);
}
button.ghost:hover{
  background:#1e2536;
}

/* --- Board and Card Styles --- */
.board{
  position:relative; 
  min-height:750px;
  background:radial-gradient(70% 70% at 50% 50%, #1a203a, #0b0f19 80%  ); 
  border:2px solid #1e2536; 
  border-radius:12px; 
  padding:20px;
  box-shadow:inset 0 0 160px rgba(0,0,0,.35), 0 8px 25px rgba(0,0,0,.35);
  overflow:visible;
}
.slot{
  position:absolute; 
  width:var(--cardW); height:var(--cardH);
  border:2px dashed #3a4569; 
  border-radius:10px;
  background:rgba(42,48,66,.15); 
  display:flex; align-items:center; justify-content:center;
  color:#8ea2ff; 
  font-size:12px; 
  text-align:center; 
  padding:4px;
}
.card{
  position:absolute; 
  width:var(--cardW); 
  height:var(--cardH);
  border-radius:10px; 
  background:var(--card); 
  border:1px solid #242a40; 
  box-shadow:0 8px 18px rgba(0,0,0,.45);
  transform-style:preserve-3d; 
  transition:transform .6s, box-shadow .2s;
  cursor:pointer; 
  user-select:none;
  z-index: 50; 
}
.card:hover{
  box-shadow:0 14px 30px rgba(0,0,0,.6);
  z-index: 60;
}
.card-inner{position:relative; width:100%; height:100%; transform-style:preserve-3d}
.face, .back{
  position:absolute; inset:0; backface-visibility:hidden; border-radius:10px; overflow:hidden;
  display:flex; align-items:center; justify-content:center; 
}
.face{
  background:linear-gradient(180deg,#242a40,#0f1329); 
  border:1px solid #3e4570;
  padding: 0; 
}
.face img{
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.back{
  transform:rotateY(180deg);
  background:repeating-conic-gradient(from 0deg, #1f2740, #1f2740 14deg, #111420 14deg, #111420 28deg);
  border:2px solid #5a5f78;
  box-shadow: inset 0 0 10px rgba(0,0,0,.5);
}
.card.reversed .face{
  transform:rotate(180deg);
}
.card.flipped .card-inner{
  transform:rotateY(180deg);
}

.overlayLabel{
  z-index: 1; 
}

.pos-label{
  position:absolute; 
  bottom:8px; 
  left:8px; 
  color:#d0ffe7; 
  font-size:12px; 
  font-weight:700;
  background:rgba(20, 51, 39, 0.85); 
  padding:4px 8px; 
  border-radius:6px;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.readCard{
  margin:10px 0; 
  padding:15px; 
  background:#0f1220; 
  border:1px solid #232a46; 
  border-radius:10px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.2);
  line-height: 1.6;
}
.readCard h5, .reading-output h3{margin:0 0 8px 0; font-size:1.1rem; color:var(--primary)}
.readCard > div{margin-top: 5px; font-size: 0.95rem; color: var(--muted);}


/* --- Modal & Toast --- */
.modal {
  /* 修正：實現全螢幕居中 */
  position: fixed; 
  inset: 0; 
  background: rgba(0,0,0,.7);
  display: flex; 
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: #101524; 
  border: 1px solid #334; 
  border-radius: 12px;
  width: 90%; 
  max-width: 900px; 
  max-height: 90%; 
  overflow-y: auto;
  padding: 30px; 
  color: #eee; 
  position: relative;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  /* 移除絕對定位或多餘的 margin/transform，確保 flex 居中生效 */
}

.modal-close{
  position: absolute; top: 12px; right: 15px;
  background: #333; border: none; color: #fff; font-size: 1.2rem;
  cursor: pointer; border-radius: 50%; width: 30px; height: 30px;
  line-height: 1; text-align: center;
  z-index: 1000;
}

.toast-message {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--secondary);
    color: white;
    padding: 12px 20px;
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 10000;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.toast-message.show {
    opacity: 1;
    transform: translate(-50%, -10px);
}

/* ------------------- CARD ZOOM FEATURE ------------------- */
.zoom-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.zoom-overlay.hidden {
    display: none;
}
.zoom-overlay.show {
    opacity: 1;
    pointer-events: auto;
    display: flex;
}

.zoomed-card-wrapper {
    position: relative;
    display: flex;
    gap: 30px;
    max-width: 80%;
    max-height: 90%;
    margin: auto;
}

.zoomed-card-content {
    width: 300px; 
    height: 475px; 
    flex-shrink: 0;
    background: none;
}
.zoomed-card-content .card{
    position: relative !important;
    left: 0 !important;
    top: 0 !important;
    transform: none !important;
    width: 100% !important;
    height: 100% !important;
    box-shadow: 0 10px 30px rgba(255, 255, 255, 0.1), 0 0 50px rgba(122, 162, 255, 0.3);
    cursor: default;
    transition: none; 
}
.zoomed-card-content .card:hover{
    box-shadow: 0 10px 30px rgba(255, 255, 255, 0.1), 0 0 50px rgba(122, 162, 255, 0.3);
    z-index: inherit;
}
.zoomed-card-content .card.flipped .card-inner{
    transform: rotateY(0deg); 
}


.zoomed-card-reading {
    flex-grow: 1;
    background: #101524;
    border: 1px solid #1e2536;
    border-radius: 12px;
    padding: 25px;
    overflow-y: auto;
    max-height: 475px;
    color: var(--ink);
}
.zoomed-card-reading h4 {
    margin-top: 0;
    color: var(--accent);
    font-size: 1.3rem;
    border-bottom: 1px solid var(--slot);
    padding-bottom: 10px;
}
.zoomed-card-reading p {
    margin-bottom: 15px;
    font-size: 1rem;
    line-height: 1.6;
}
.zoomed-card-reading .keywords {
    font-weight: 600;
    color: var(--primary);
}

@media (max-width: 768px) {
    .zoomed-card-wrapper {
        flex-direction: column;
        max-width: 95%;
        gap: 20px;
    }
    .zoomed-card-content {
        width: 250px;
        height: 395px;
        margin: 0 auto;
    }
    .zoomed-card-reading {
        max-height: 300px;
    }
}
